DEV Community

Discussion on: User Agent string difference in Puppeteer headless and headful

Collapse
 
mcdrecords profile image
M.C.D

Hello sir,
could you help me please?
I would like to load random useragent for each page lunch.
How do i do that?
Example:
page.setUserAgent('/utils/referers.txt');

thank you

Collapse
 
j2403sam profile image
Sam

I would have a variable called userAgents that is an array of user agent strings then do something like

await page.setUserAgent(userAgents[Math.floor(Math.random()*userAgents.length)]);

Collapse
 
mouhannadlrx profile image
Mouhannad

I logged in just to add like to this comment

Thread Thread
 
sonyarianto profile image
Sony AK

thank you :)