Skip to content

[Bug]: Promise was collected in cross frame promises #41826

Description

@goloveychuk

Version

1.58.2

Steps to reproduce

Reproducing is hard, it requires GC calls from browser.

on playwright side

page.evaluate('someFunction')

On main frame

window.someFunction = () => iframeWindow.someOtherFunction()

On iframe

window.someOtherFunction = () => Promise.resolve()

Somewhere on that time GC need to happen and clean promise from iframe.

Expected behavior

Ideally we need to fix cross-frames promises GC, but idk if it's possible because it seems like cdp issue.
If there is no solution, at least we need to write a meaningful msg about what happened in error message.
Either add cdp error message to playwright error description or map it to a description for developers to help solve the issue.

Actual behavior

Playwright side throws
page.evaluate: Execution context was destroyed, most likely because of a navigation.

Additional context

In cdp debug I see a

{
  "method": "Runtime.callFunctionOn",
  "params": {
    "functionDeclaration": "(utilityScript, ...args) => utilityScript.evaluate(...args)",
    "objectId": "...",
    "arguments": [
      { "objectId": "..." },
      { "value": true },
      { "value": true },
      {
        "value": "(function anonymous() { return __SomeE2EApi__.waitForChangesAppliedAsync() })"
      },
      { "value": 1 },
      { "value": { "v": "undefined" } }
    ],
    "returnByValue": true,
    "awaitPromise": true,
    "userGesture": true
  }

{"code":-32000,"message":"Promise was collected"}

To fix (I don't see the error after this change but I cannot have 100% proof that this fix works) the issue I've changed the implementation from

waitForChangesAppliedAsync = () => iframeWindow.waitForChangesAppliedAsync() 

to

waitForChangesAppliedAsync = async () => {
  await iframeWindow.waitForChangesAppliedAsync() 
}

which creates promise on main frame instead of passthrough iframe promise.

Reproduced on macos local browser and linux with remote browser pool on k8s pods on different chrome versions.
Not a env-dependent issue.

Environment

System:
    OS: macOS 26.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 70.80 MB / 32.00 GB
  Binaries:
    Node: 24.10.0 - /Users/vadymh/.local/state/fnm_multishells/63441_1783516106428/bin/node
    Yarn: 1.22.19 - /Users/vadymh/.local/state/fnm_multishells/63441_1783516106428/bin/yarn
    npm: 11.6.1 - /Users/vadymh/.local/state/fnm_multishells/63441_1783516106428/bin/npm
  IDEs:
    VSCode: 1.128.0 - /usr/local/bin/code
    Cursor: 3.1.10 - /usr/local/bin/cursor
    Claude Code: 2.1.202 - /Users/vadymh/.local/bin/claude
    Codex: 0.142.5 - /Users/vadymh/.local/bin/codex
  Languages:
    Bash: 3.2.57 - /bin/bash

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

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