Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unhandled promise rejection in case of binded function called with detached frame #7814

Closed
mmedvedik opened this issue Nov 30, 2021 · 6 comments · Fixed by #8024
Closed
Labels

Comments

@mmedvedik
Copy link

mmedvedik commented Nov 30, 2021

Steps to reproduce the problem:

  1. On a page with an iframe bind puppeteer function using page.exposeFunction;
  2. Detach iframe;
  3. Call bounded function;

Actual result: Unhandled promise rejection. Output attached.

Detached frame`s lifecycle events from the debugger:

  • init
  • DOMContentLoaded
  • load
  • networkAlmostIdle
  • networkIdle

Seems that CDPSession does not clean the detached frame from the 'Runtime.addBinding' chrome event listeners.

this._client.on('Runtime.bindingCalled', (event) =>
this._onBindingCalled(event)
);

Puppeteer version

puppeteer-core 11.0.0

Node.js version

v14.17.1

npm version

6.14.13

What operating system are you seeing the problem on?

Linux, macOS

Relevant log output

UnhandledPromiseRejectionWarning: Error: Execution context is not available in detached frame https://www.site.com/iframe_url/index.html (are you trying to evaluate?)

    at DOMWorld.executionContext (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/DOMWorld.js:86:19)

    at DOMWorld._onBindingCalled (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/DOMWorld.js:372:36)

    at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/DOMWorld.js:55:66

    at /usr/src/app/node_modules/puppeteer-core/lib/cjs/vendor/mitt/src/index.js:51:62

    at Array.map (<anonymous>)

    at Object.emit (/usr/src/app/node_modules/puppeteer-core/lib/cjs/vendor/mitt/src/index.js:51:43)

    at CDPSession.emit (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.js:72:22)

    at CDPSession._onMessage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:245:18)

    at Connection._onMessage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:117:25)

    at WebSocket.<anonymous> (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/NodeWebSocketTransport.js:13:32)
@mstr-pezhang
Copy link

Encountered the same problem too.
Not sure if it's caused by 4d9dc8c

@jfirebaugh
Copy link

On node.js 15+ unhandled promise rejections exit the process immediately by default, so this error ends the puppeteer script entirely.

@Adeloyd
Copy link

Adeloyd commented Jan 31, 2022

This is a problem in chrome. In version 901912, everything works without errors, if you take 950341, then an error.

const browserFetcher = puppeteer.createBrowserFetcher();
const revisionInfo = await browserFetcher.download('901912');
let options = {
  executablePath: revisionInfo.executablePath    
}
const browser = await puppeteer.launch(options);
const page = await browser.newPage();

@chopen
Copy link

chopen commented Feb 1, 2022

Ran into this same issue this weekend. LMK if anyone needs help testing or isolating. -ch

@triplewy
Copy link

triplewy commented Feb 6, 2022

@Adeloyd Can confirm this works. Do you know the underlying root cause in Chromium that is causing this bug?

@akhfaern
Copy link

i've come across the same issue and fixed with
aw1875/puppeteer-hcaptcha#22 (comment)

can you patch it up ?

pmmmwh added a commit to pmmmwh/puppeteer that referenced this issue Feb 15, 2022
OrKoN pushed a commit to pmmmwh/puppeteer that referenced this issue Feb 15, 2022
OrKoN pushed a commit to pmmmwh/puppeteer that referenced this issue Feb 17, 2022
OrKoN added a commit that referenced this issue Feb 17, 2022
* fix: ensure dom binding is not called after detatch

Fixes #7814

* refactor: detach listeners instead

* refactor: safer approach

* fix: test in test/page.spec.ts

Co-authored-by: Alex Rudenko <OrKoN@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants