Skip to content

Commit

Permalink
Document setting user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mfeckie authored and coreyti committed Sep 26, 2024
1 parent b717839 commit b2a03a6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion man/guides/browsers.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# Browsers

...
## Setting a custom user agent

It's possible to set the user agent to a custom value via `BrowserContext` or `Browser`
### With Browser

```elixir
page = Playwright.Browser.new_page(browser, %{"userAgent" => "My Custom Agent"})
```

### With BrowserContext

```elixir
context = Browser.new_context(browser, %{"userAgent" => "Special Agent"})
```

## Custom Agent and Phoenix / Ecto

Setting a custom agent can be particularly useful when running Playwright in tests with the database involved.

Follow https://hexdocs.pm/phoenix_ecto/Phoenix.Ecto.SQL.Sandbox.html and set the `userAgent` to the result of `Phoenix.Ecto.SQL.Sandbox.metadata_for(YourApp.Repo, pid)`


0 comments on commit b2a03a6

Please sign in to comment.