-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)` | ||
|
||
|