Skip to content

Commit

Permalink
chore: fix random ua generation (#13356)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Sep 21, 2023
1 parent cfe8569 commit eb1a40a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/rand-user-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/utils/rand-user-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit eb1a40a

Please sign in to comment.