Repository navigation
page-script: reply to an evaluate before reporting its navigation - #246
Merged
Merged
Conversation
LuisDuarte1
requested review from
BernardoPe,
celso,
jonnyparris and
ruifigueira
as code owners
November 26, 2026 11:19
An evaluate that assigned location to another document rejected with "Execution context was destroyed", and Playwright's page-autowaiting-no-hang "assigning location to about:blank" failed on main. A cross-document location change reports the navigation from a native setTimeout(0) so that the evaluate replies first. Since c844cad the reply drain waits one native macrotask of its own when no page task is due, and that macrotask runs after the earlier report: the engine started the navigation and retired the context while the reply was still pending. Hold such a report while yieldToDuePageTasks drains for a reply, and queue it as a fresh setTimeout(0) when the drain ends. No macrotask runs between the end of the drain and the reply, so the reply goes first again, and the drain keeps the macrotask that lets long page promise chains finish. Signed-off-by: Luís Duarte <lduarte@cloudflare.com>
LuisDuarte1
force-pushed
the
lduarte/fix-post-eval-skip-navigation
branch
from
November 26, 2026 11:25
22356a1 to
737c685
Compare
Three page-evaluate tests navigate from inside the evaluate and failed with "Execution context was destroyed": the navigation report could still run before the evaluate's reply. Now that the report waits for that reply, they pass. Signed-off-by: Luís Duarte <lduarte@cloudflare.com>
LuisDuarte1
enabled auto-merge (rebase)
November 26, 2026 11:37
Collaborator
|
beep-boop-bernardo-agent-🤖 No blocking or non-blocking findings. Agent review: APPROVE sha=83a45438c7a8c2047e88b97efb4ce32b3ee21357 |
ruifigueira
approved these changes
Nov 26, 2026
ruifigueira
added a commit
that referenced
this pull request
Nov 27, 2026
The pinned WebMCP IDL (spec PRs #241, #246, #251, #253, #254, #348) changed what getTools() returns and what executeTool() and registerTool() accept. getTools() still returned RegisteredTool dictionaries, and executeTool() found a tool by name, parsed a JSON string and rejected every failure with UnknownError. getTools() now returns instances of the exposed Tool interface, with source instead of window, and null inputSchema, outputSchema and annotations when the tool has none. Each Tool keeps the ID of the registration it came from, and executeTool() runs only that registration, so a same-named tool registered later is a NotFoundError. A plain object is not a Tool and rejects with TypeError. A Tool is a Proxy over its instance, so structuredClone() throws DataCloneError and JSON.stringify() gives {}. executeTool() takes an optional object, not a JSON string. A primitive, or input that JSON cannot serialize, rejects with TypeError. A failed tool or an unserializable result rejects with OperationError, as the spec's tool execution errors say. registerTool() converts its dictionary as WebIDL does, validates and stores outputSchema like inputSchema, and keeps the debugging annotation. beep-boop-🤖 Signed-off-by: Rui Figueira <rfigueira@cloudflare.com>
ruifigueira
added a commit
that referenced
this pull request
Nov 27, 2026
The pinned WebMCP IDL (spec PRs #241, #246, #251, #253, #254, #348) changed what getTools() returns and what executeTool() and registerTool() accept. getTools() still returned RegisteredTool dictionaries, and executeTool() found a tool by name, parsed a JSON string and rejected every failure with UnknownError. getTools() now returns instances of the exposed Tool interface, with source instead of window, and null inputSchema, outputSchema and annotations when the tool has none. Each Tool keeps the ID of the registration it came from, and executeTool() runs only that registration, so a same-named tool registered later is a NotFoundError. A plain object is not a Tool and rejects with TypeError. A Tool is a Proxy over its instance, so structuredClone() throws DataCloneError and JSON.stringify() gives {}. executeTool() takes an optional object, not a JSON string. A primitive, or input that JSON cannot serialize, rejects with TypeError. A failed tool or an unserializable result rejects with OperationError, as the spec's tool execution errors say. registerTool() converts its dictionary as WebIDL does, validates and stores outputSchema like inputSchema, and keeps the debugging annotation. beep-boop-🤖 Signed-off-by: Rui Figueira <rfigueira@cloudflare.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the Playwright lane on
main, red since #230 merged:page-autowaiting-no-hang.spec.ts,"assigning location to about:blank", fails with
page.evaluate: Execution context was destroyed.Every pull request since then fails the lane too.
A cross-document location change (
location.href = ...,assign, ...) reports the navigation tothe engine from a native
setTimeout(0), so that the evaluate which set the location replies beforethe engine starts the navigation and retires the context. Since c844cad ("wait one native
macrotask on the post-eval skip path"),
yieldToDuePageTaskswaits one nativesetTimeout(0)of itsown when no page task is due. That timer is queued after the report, so the report runs first, the
engine starts the navigation, and the evaluate's reply arrives after the context is gone.
Behavior and API impact
An evaluate (or WebMCP tool call) that assigns location to another document replies with its result
again, before
Runtime.executionContextDestroyedand the navigation's other events, as in Chrome.The navigation itself is unchanged.
Playwright: besides
page-autowaiting-no-hang.spec.ts, threepage-evaluate.spec.tstests thatnavigate from inside the evaluate, pinned FAIL with "Execution context was destroyed", now pass:
"should throw a nice error after a navigation" and both "should not throw an error when evaluation
does a synchronous navigation" tests. The second commit removes their pins, as
//tests/pw:update_expectationsdoes for a test that passes.Implementation
page-tasks.tsgainsrunAfterPendingReply(task). WhileyieldToDuePageTasksis draining for areply, it holds the task, and when the drain ends it queues each held task as a fresh
setTimeout(0). No macrotask runs between the end of the drain and the reply, so the reply goesfirst. The navigation report in
setCurrentUrlruns through it. The drain keeps its nativemacrotask, so the long page promise chains c844cad fixed still finish before the reply.
Validation
packages/engine/test/e2e/evaluate-location-assign-reply.e2e.test.ts: navigates to a fixturepage, sends
Runtime.evaluate("window.location.href = \"about:blank\"")and records CDP events.It checks that the reply comes before any navigation event, carries
"about:blank", and that theframe then navigates to
about:blank.mainit fails:Protocol error (Runtime.evaluate): Execution context was destroyed.page-tasks.tschange reverted, the reply comes first in 3 of 3 runs, whichplaces the regression there.
pnpm run test:e2e --maxWorkers=2 evaluate-location-assign-reply eval-microtask-chain-console location-assign-navigates eval-across-navigation eval-during-navigate input-navigation-reply script-navigation-tab window-navigation webmcp: 9 files, 30 tests pass.bazel test //packages/engine:vitest --test_sharding_strategy=disabled --test_arg=page-task-yield:8 tests pass.
pnpm run check: the 32 tests of//:checkother than//packages/core/pkg:memprof_buildpass(no Rust changes), and
//scripts:workspace_checkspasses.pnpm run lint:jsandpnpm run format:checkare clean.the fix reported only the three unexpected passes above.
Risks and follow-ups
A navigation report that lands during a reply drain now goes out up to one macrotask later than
before; nothing reads it before the reply. Separately, the
about:blankdocument the engine loadsreports
location.hrefashttps://kitesurf.local/instead ofabout:blank; this change does nottouch that.
Checklist
Signed-off-byline (git commit -s); see CONTRIBUTING.md.