Custom user agent playwright browser

how can put a custom user agent into the playwright crawler context?
No description
8 Replies
harsh-harlequin
harsh-harlequinOP2y ago
Like the image above
harsh-harlequin
harsh-harlequinOP2y ago
I Already tried, but it doesn't set the user agent in the browser, just the header.
like-gold
like-gold2y ago
what do you mean by that? If you see it the headers - it means it's set. If you see this user-agent in browser request headers - it means it's set
harsh-harlequin
harsh-harlequinOP2y ago
My crawlee is printing this agent
No description
harsh-harlequin
harsh-harlequinOP2y ago
i want this 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63'
harsh-harlequin
harsh-harlequinOP2y ago
I tried to put but not work
No description
like-gold
like-gold2y ago
Got it. This should work:
const crawler = new PlaywrightCrawler({
launchContext: {
launchOptions: {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63'
}
},
...
const crawler = new PlaywrightCrawler({
launchContext: {
launchOptions: {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63'
}
},
...
and maybe also switch off fingerprints (but not necessary): browserPoolOptions: { useFingerprints: false }, as another crawler option

Did you find this page helpful?