Skip to content

fix(emulation): clear the geolocation override instead of pinning to 0,0 - #3145

Closed
nancy6547 wants to merge 1 commit into
ChromeDevTools:mainfrom
nancy6547:fix/emulate-clear-geolocation
Closed

nancy6547 wants to merge 1 commit into
ChromeDevTools:mainfrom
nancy6547:fix/emulate-clear-geolocation

Conversation

@nancy6547

Copy link
Copy Markdown
Contributor

Closes #2964

emulate documents geolocation as "Omit to clear the geolocation override", but McpPage.emulate() called setGeolocation({latitude: 0, longitude: 0}). Every emulate call without geolocation (even one that only changes the color scheme) pinned the page to 0,0, and there was no way back to the real position.

Puppeteer has no API to remove the override, so this sends CDP Emulation.clearGeolocationOverride on the page's session instead.

Tests:

  • McpPage unit test: omitting geolocation sends Emulation.clearGeolocationOverride instead of a second setGeolocation call (the old test asserted the (0, 0) behaviour).
  • New real-browser test in emulation.test.ts: grant the geolocation permission, emulate a position and read it back, then call emulate({}). The page no longer reports 0,0 (it did on main).

@OrKoN
OrKoN self-requested a review October 15, 2026 11:57
Comment thread src/McpPage.ts

if (!options.geolocation) {
await page.setGeolocation({latitude: 0, longitude: 0});
// Puppeteer has no API to remove the override, and setting (0, 0) would

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix this in Puppeteer first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I’ll send a Puppeteer PR that lets page.setGeolocation(null) remove the override, and update this PR to use it once it’s released.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OrKoN OrKoN closed this in #3265 Oct 20, 2026
johan-gorter pushed a commit to johan-gorter/chrome-devtools-mcp that referenced this pull request Oct 20, 2026
…omeDevTools#3265)

This PR applies the review comments from two stale PRs. A reviewer
requested changes on each PR more than 2 days ago. There are two
commits, one for each fix.

## take_snapshot timeout (from ChromeDevTools#3227)

- `take_snapshot` waited for Puppeteer's `protocolTimeout` (180 s) when
the page did not return the accessibility tree. The tool held the tool
lock during this time.
- `TextSnapshot.create()` now rejects after 10 s. The error tells the
agent to navigate, reload, or select another page.
- Review request: "extract a re-usable helper or better use the Deferred
class from Puppeteer". This PR adds `withTimeout()` in
`src/utils/timeout.ts`. It uses Puppeteer's `Deferred.race`.
`src/third_party/index.ts` exports `Deferred`.
- In this PR, only `TextSnapshot` calls `withTimeout()`. A separate PR
can move the other timeout races to it.

## emulate geolocation (from ChromeDevTools#3145)

- `emulate` without `geolocation` set the position to latitude 0,
longitude 0. The tool description says that this clears the override.
- Review request: "fix this in Puppeteer first".
puppeteer/puppeteer#15590 adds `page.setGeolocation(null)`, and it ships
in Puppeteer 25.15.0. This repository already uses 25.15.0.
`McpPage.emulate()` now calls `setGeolocation(null)` and does not use an
internal API.
- User-visible change: each `emulate` call without `geolocation` now
removes the geolocation override. Before, it set the position to 0,0.

## Tests

- `tests/utils/timeout.test.ts`: the helper returns the value when the
promise settles first. It rejects with `TimeoutError` when the promise
does not settle in time.
- `tests/TextSnapshot.test.ts`: a never-resolving
`accessibility.snapshot` rejects after 10 s. The test fails on `main`.
- `tests/McpPage.test.ts`: `emulate({})` calls `setGeolocation(null)`.
The test fails on `main`.
- `npm run test` passes.

Closes ChromeDevTools#3227
Closes ChromeDevTools#3145
Fixes ChromeDevTools#2939
Fixes ChromeDevTools#2964

Co-authored-by: Rudy Mizrahi Celekli
<[email protected]>
Co-authored-by: nancy <[email protected]>

---------

Co-authored-by: Rudy Mizrahi Celekli <[email protected]>
Co-authored-by: nancy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

emulate without geolocation pins the page to latitude 0, longitude 0 instead of clearing the override

2 participants