Repository navigation
Document browser location controls #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+112
−0
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6df24c2
Document browser location controls
tnsardesai 233a320
Describe browser location validation and normalization
tnsardesai 49e6d7b
Document explicit browser location with region defaults
tnsardesai 1b3d90a
Link browser location defaults to regions
tnsardesai bc35fe2
Document synchronous browser location updates
tnsardesai 2b6b4bd
Document that reused pool browsers keep their location
tnsardesai 9c99878
Document the unsupported-image create response
tnsardesai 3f7b8b7
Explain what a failed location update leaves applied
tnsardesai e431b9b
Shorten the location entry on the configure page
tnsardesai ad504ba
Describe browser location as it behaves once fully rolled out
tnsardesai 67e04bd
Merge branch 'main' into hypeship/browser-location-docs
tnsardesai 4d9d122
Simplify the browser location page
tnsardesai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| --- | ||
| title: "Browser Location" | ||
| description: "Set a browser session's timezone and locale, or use the defaults for its region" | ||
| --- | ||
|
|
||
| Each browser session has one timezone and one formatting locale. By default, both come from the [region](/browsers/regions) the browser runs in, for example `America/New_York` and `en-US` for a browser in `us-east`. Set either field to override it for the session. | ||
|
|
||
| The setting applies across browser contexts, pages, frames, workers, `Intl`, `navigator.language`, `navigator.languages`, and future `Accept-Language` headers. Updating it doesn't restart Chromium or reload pages. | ||
|
|
||
| <Note> | ||
| Location controls timezone and language behavior. It doesn't set geolocation coordinates, grant geolocation permission, change the system clock, translate browser UI, or guarantee a bot-detection outcome. | ||
| </Note> | ||
|
|
||
| ## Set location when creating a browser | ||
|
|
||
| Set either field independently. An omitted field uses the default for the browser's region. | ||
|
|
||
| <CodeGroup> | ||
| ```typescript TypeScript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const kernel = new Kernel(); | ||
| const browser = await kernel.browsers.create({ | ||
| location: { | ||
| timezone: 'Europe/Berlin', | ||
| locale: 'de-DE', | ||
| }, | ||
| }); | ||
|
|
||
| console.log(browser.location); | ||
| ``` | ||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| kernel = Kernel() | ||
| browser = kernel.browsers.create( | ||
| location={ | ||
| "timezone": "Europe/Berlin", | ||
| "locale": "de-DE", | ||
| }, | ||
| ) | ||
|
|
||
| print(browser.location) | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| `timezone` accepts IANA identifiers such as `America/Los_Angeles`. `locale` accepts BCP 47 tags such as `en-US` or `de-DE` that the browser formats dates and numbers for with that exact region. KERNEL normalizes spelling and deprecated codes, so `en-us` becomes `en-US` and `iw-IL` becomes `he-IL`. An unsupported value such as `en-QQ` returns a `400` with code `invalid_browser_location`. | ||
|
|
||
| ## Update a running browser | ||
|
|
||
| Use `browsers.update()` to change the location of a running browser: | ||
|
|
||
| <CodeGroup> | ||
| ```typescript TypeScript | ||
| // Set a field to override it. Fields you leave out keep their current value. | ||
| await kernel.browsers.update(browser.session_id, { | ||
| location: { | ||
| timezone: 'America/Los_Angeles', | ||
| locale: 'en-US', | ||
| }, | ||
| }); | ||
|
|
||
| // Set a field to null to go back to the default for the browser's region. | ||
| await kernel.browsers.update(browser.session_id, { | ||
| location: { timezone: null }, | ||
| }); | ||
| ``` | ||
|
|
||
| ```python Python | ||
| # Set a field to override it. Fields you leave out keep their current value. | ||
| kernel.browsers.update( | ||
| browser.session_id, | ||
| location={ | ||
| "timezone": "America/Los_Angeles", | ||
| "locale": "en-US", | ||
| }, | ||
| ) | ||
|
|
||
| # Set a field to None to go back to the default for the browser's region. | ||
| kernel.browsers.update( | ||
| browser.session_id, | ||
| location={"timezone": None}, | ||
| ) | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| ## Read effective location | ||
|
|
||
| Browser responses include the timezone and locale the browser is using, and whether each one is your override or the region's default: | ||
|
|
||
| ```json | ||
| { | ||
| "location": { | ||
| "timezone": "America/Los_Angeles", | ||
| "locale": "en-US", | ||
| "timezone_source": "override", | ||
| "locale_source": "metro" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## How changes take effect | ||
|
|
||
| - Open tabs pick up a change right away, without reloading. | ||
| - New tabs and frames start with the current timezone and locale. | ||
| - Date and number formatters a page already created keep their original settings. Create a new one, such as `new Intl.DateTimeFormat()`, to use the new values. | ||
| - Requests already in progress keep their original language. Later requests use the new one. | ||
| - A timezone or locale you set yourself through Playwright or Puppeteer, such as Playwright's `timezoneId`, takes precedence on the pages it applies to. | ||
| - The location lasts for the browser session. Profiles don't save it. | ||
| - A pooled browser you release with `reuse: true` keeps its location for the next acquirer, just as it keeps cookies and open tabs. Release it with `reuse: false` to get a fresh browser instead. | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tnsardesai - I missed this in the initial API review probably. I'm generally -1 to exposing
metrolanguage (idk if we've already leaked that in other places). I think we coulds/metro/defaultfor both source fields instead. Can be resolved outside of this PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm. yea that's fair! I don't have any strong opinions on this so okay with just replacing it with default! I can spin up a quick PR for it