Skip to content

Commit 450da16

Browse files
authored
Update playwright.mdx
Setting custom user agent in Playwright
1 parent 30c7893 commit 450da16

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ const browser = await playwright.launch(env.MYBROWSER, { keep_alive: 600000 });
201201

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

204+
### Setting a Custom User Agent
205+
206+
To specify a custom user agent in Playwright, set it in the options when creating a new browser context with `browser.newContext()`. All pages subsequently created from this context will use the new user agent.
207+
208+
use the `page.setUserAgent()` method. This is useful if the target website serves different content based on the user agent.
209+
210+
```js
211+
const context = await browser.newContext({
212+
userAgent:
213+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
214+
});
215+
```
216+
217+
Note: Modifying `UserAgent` will not bypass bot protection as requests from Browser Rendering will always be identified as a bot.
218+
219+
204220
## Session management
205221

206222
In order to facilitate browser session management, we have extended the Playwright API with new methods:

0 commit comments

Comments
 (0)