Skip to content

Commit 30c7893

Browse files
authored
Update puppeteer.mdx
set custom user agent on puppeteer
1 parent 3e9068f commit 30c7893

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/content/docs/browser-rendering/platform/puppeteer.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ const browser = await puppeteer.launch(env.MYBROWSER, { keep_alive: 600000 });
5757

5858
Using the above, the browser will stay open for up to 10 minutes, even if inactive.
5959

60+
### Setting a Custom User Agent
61+
62+
To specify a custom user agent in Puppeteer, use the `page.setUserAgent()` method. This is useful if the target website serves different content based on the user agent.
63+
64+
```js
65+
await page.setUserAgent(
66+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
67+
);
68+
```
69+
70+
Note: Modifying `userAgent` will not bypass bot protection as requests from Browser Rendering will always be identified as a bot.
71+
6072
## Session management
6173

6274
In order to facilitate browser session management, we've added new methods to `puppeteer`:

0 commit comments

Comments
 (0)