Skip to content

page-script: reply to an evaluate before reporting its navigation - #246

Merged
LuisDuarte1 merged 2 commits into
mainfrom
lduarte/fix-post-eval-skip-navigation
Nov 26, 2026
Merged

LuisDuarte1 merged 2 commits into
mainfrom
lduarte/fix-post-eval-skip-navigation

Conversation

@LuisDuarte1

@LuisDuarte1 LuisDuarte1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

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 to
the engine from a native setTimeout(0), so that the evaluate which set the location replies before
the engine starts the navigation and retires the context. Since c844cad ("wait one native
macrotask on the post-eval skip path"), yieldToDuePageTasks waits one native setTimeout(0) of its
own 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.executionContextDestroyed and the navigation's other events, as in Chrome.
The navigation itself is unchanged.

Playwright: besides page-autowaiting-no-hang.spec.ts, three page-evaluate.spec.ts tests that
navigate 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_expectations does for a test that passes.

Implementation

page-tasks.ts gains runAfterPendingReply(task). While yieldToDuePageTasks is draining for a
reply, 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 goes
first. The navigation report in setCurrentUrl runs through it. The drain keeps its native
macrotask, so the long page promise chains c844cad fixed still finish before the reply.

Validation

  • New packages/engine/test/e2e/evaluate-location-assign-reply.e2e.test.ts: navigates to a fixture
    page, 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 the
    frame then navigates to about:blank.
    • On main it fails: Protocol error (Runtime.evaluate): Execution context was destroyed.
    • With only c844cad's page-tasks.ts change reverted, the reply comes first in 3 of 3 runs, which
      places the regression there.
    • With this change it passes.
  • 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 //:check other than //packages/core/pkg:memprof_build pass
    (no Rust changes), and //scripts:workspace_checks passes. pnpm run lint:js and
    pnpm run format:check are clean.
  • Not run here: the Playwright lane itself, which this pull request's CI runs. Its first run with
    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:blank document the engine loads
reports location.href as https://kitesurf.local/ instead of about:blank; this change does not
touch that.

Checklist

  • This pull request solves one problem; see CONTRIBUTING.md.
  • Every commit has a Signed-off-by line (git commit -s); see CONTRIBUTING.md.
  • Added or updated focused tests for behavior changes.
  • Updated documentation and generated files, or confirmed they do not apply.

@github-actions github-actions Bot added the vouch:trusted Author is vouched, a collaborator, or a bot. label Nov 26, 2026
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
LuisDuarte1 force-pushed the lduarte/fix-post-eval-skip-navigation branch from 22356a1 to 737c685 Compare November 26, 2026 11:25
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
LuisDuarte1 enabled auto-merge (rebase) November 26, 2026 11:37
@BernardoPe BernardoPe self-assigned this Nov 26, 2026
@BernardoPe

Copy link
Copy Markdown
Collaborator

beep-boop-bernardo-agent-🤖

No blocking or non-blocking findings.

Agent review: APPROVE sha=83a45438c7a8c2047e88b97efb4ce32b3ee21357

@BernardoPe BernardoPe added the Ready for human review An independent agent reviewed this exact commit and found nothing blocking label Nov 26, 2026
@BernardoPe BernardoPe removed their assignment Nov 26, 2026
@LuisDuarte1
LuisDuarte1 merged commit 797ffdc into main Nov 26, 2026
14 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for human review An independent agent reviewed this exact commit and found nothing blocking vouch:trusted Author is vouched, a collaborator, or a bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants