From eb1a40aa882dcdb7ea7d4007a1e070d86fa69516 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 22 Sep 2023 03:32:48 +0800 Subject: [PATCH] chore: fix random ua generation (#13356) --- lib/utils/rand-user-agent.js | 2 +- test/utils/rand-user-agent.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/utils/rand-user-agent.js b/lib/utils/rand-user-agent.js index c1b915256..34d819f7d 100644 --- a/lib/utils/rand-user-agent.js +++ b/lib/utils/rand-user-agent.js @@ -16,7 +16,7 @@ module.exports = ({ browser = 'chrome', os = 'mac os', device = 'desktop' }) => let UA = randUserAgent(device, browser, os); if (browser === 'chrome') { - while (UA.includes('Chrome-Lighthouse') || UA.includes('Gener8') || UA.includes('HeadlessChrome') || UA.includes('SMTBot')) { + while (UA.includes('Chrome-Lighthouse') || UA.includes('Gener8') || UA.includes('HeadlessChrome') || UA.includes('SMTBot') || UA.includes('Electron') || UA.includes('Code')) { UA = randUserAgent(device, browser, os); } } diff --git a/test/utils/rand-user-agent.js b/test/utils/rand-user-agent.js index f065e94db..01b2cc5b9 100644 --- a/test/utils/rand-user-agent.js +++ b/test/utils/rand-user-agent.js @@ -12,6 +12,13 @@ describe('rand-user-agent', () => { const match = uaArr.find((e) => !!(e.includes('Chrome-Lighthouse') || e.includes('HeadlessChrome'))); expect(match).toBeFalsy(); }); + it('chrome should not include electron', () => { + const uaArr = Array(100) + .fill() + .map(() => randUserAgent({ browser: 'chrome', os: 'windows' })); + const match = uaArr.find((e) => !!e.includes('Electron')); + expect(match).toBeFalsy(); + }); it('should has default random ua', async () => { nock('https://rsshub.test')