Skip to content

[Bug]: Misleading error message Execution context was destroyed, most likely because of a navigation. #40940

@AriPerkkio

Description

@AriPerkkio

Version

1.60.0

Steps to reproduce

https://github.com/AriPerkkio/playwright-repro-misleading-evaluate-error

  1. git clone git@github.com:AriPerkkio/playwright-repro-misleading-evaluate-error.git
  2. pnpm install
  3. pnpm test

Expected behavior

Test case with 200 should error with clear error message indicating return value is too large. It should not mention misleading errors about page navigation. Users may spend hours debugging navigation related code while real reason is large payload.

for (const depth of [50, 200]) {
  test(`repro with depth ${depth}`, async ({ page }) => {
    await page.goto("/"); // Any page

    await page.evaluate((_depth) => {
      let node = {};

      for (let i = 0; i < _depth; i++) {
        node = { child: node };
      }

      return node;
    }, depth);
  });
}

I would expect error like:

  ✓  1 example.test.ts:4:7 › repro with depth 50 (60ms)
  ✘  2 example.test.ts:4:7 › repro with depth 200 (52ms)


  1) example.test.ts:4:7 › repro with depth 200 ────────────────────────────────────────────────────

    Error: page.evaluate: Returned too deep object. Limit is <some-number>.

       5 |     await page.goto("/");
       6 |
    >  7 |     await page.evaluate((_depth) => {

Actual behavior

  ✓  1 example.test.ts:4:7 › repro with depth 50 (60ms)
  ✘  2 example.test.ts:4:7 › repro with depth 200 (52ms)


  1) example.test.ts:4:7 › repro with depth 200 ────────────────────────────────────────────────────

    Error: page.evaluate: Execution context was destroyed, most likely because of a navigation.

       5 |     await page.goto("/");
       6 |
    >  7 |     await page.evaluate((_depth) => {
         |                ^
       8 |       let node = {};
       9 |
      10 |       for (let i = 0; i < _depth; i++) {
        at /x/playwright-evaluate-error/example.test.ts:7:16

Additional context

Thanks for working on Playwright, it's awesome. ❤️

Environment

System:
    OS: macOS 26.5
    CPU: (14) arm64 Apple M4 Pro
    Memory: 1.93 GB / 24.00 GB
  Binaries:
    Node: 22.22.0 - /x/.nvm/versions/node/v22.22.0/bin/node
    pnpm: 10.33.4 - /Ux/.nvm/versions/node/v22.22.0/bin/pnpm
  IDEs:
    VSCode: 1.120.0 - /usr/local/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @playwright/test: 1.60.0 => 1.60.0 
    playwright: 1.60.0 => 1.60.0

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions