Tran
Tran

Reputation: 179

Puppeteer Random user-agent args

Recently I asked this random useragents from .json file but the thing is that after I added "capture screen" of puppeteer it keeps showing headless chrome, so I copied the previous topic answer into wrong place.

Now the real useragent js page came from this page:

const browser = await puppeteer.launch({
headless: false,
args: ['--headless', '--disable-infobars', '--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36', '--no-sandbox', `--proxy-server=socks5://127.0.0.1:${port}`] : ['--no-sandbox'],

});

So how do I create rnadom list inside the arguments? My previous help which doesnt worked for me as the random useragents code was not in correct place is here: Puppeteer browser useragent list

But adding that code inside this wont work.

So after --user-agent= I want to add "random" function but how?

Upvotes: 3

Views: 7963

Answers (1)

Fortdev
Fortdev

Reputation: 305

You can use the user-agents module. You should install npm install user-agents

const UserAgent = require("user-agents");
const userAgent = new UserAgent({
   deviceCategory: "desktop",
   platform: "Linux x86_64",
 });

Then in the head "--user-agent=" + userAgent + "",

Upvotes: 8

Related Questions