puppeteer: tweak the ua a bit

This commit is contained in:
yanlong.wang 2025-02-19 14:05:26 +08:00
parent cf24d84e8a
commit 2991e300d8
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -466,6 +466,7 @@ export class PuppeteerControl extends AsyncService {
livePages = new Set<Page>();
pagePhase = new WeakMap<Page, 'idle' | 'active' | 'background'>();
lastPageCratedAt: number = 0;
ua: string = '';
rpsCap: number = 500;
lastReqSentAt: number = 0;
@ -527,7 +528,8 @@ export class PuppeteerControl extends AsyncService {
}
process.nextTick(() => this.serviceReady());
});
this.logger.info(`Browser launched: ${this.browser.process()?.pid}`);
this.ua = await this.browser.userAgent();
this.logger.info(`Browser launched: ${this.browser.process()?.pid}, ${this.ua}`);
this.emit('ready');
@ -566,6 +568,7 @@ export class PuppeteerControl extends AsyncService {
}
const preparations = [];
preparations.push(page.setUserAgent(this.ua.replace(/Headless/i, '')));
// preparations.push(page.setUserAgent(`Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)`));
// preparations.push(page.setUserAgent(`Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; GPTBot/1.0; +https://openai.com/gptbot)`));
preparations.push(page.setBypassCSP(true));