Protocol error (Runtime.callFunctionOn): Target closed.
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 5.5.0
- Platform / OS version: macOS 10.15.7
- URLs (if applicable): -
- Node.js version: v14.15.0
What steps will reproduce the problem?
Please include code that reproduces the issue.
- Open page
- Wait for non-existent selector
- Close page
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
// not await!
page.waitForSelector('.non-existent').then(() => console.log('it should never happened));
await page.close();
What is the expected result?
Closing the page normally without errors.
What happens instead?
Error: Protocol error (Runtime.callFunctionOn): Target closed.
at /app/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208:63
at new Promise (<anonymous>)
at CDPSession.send (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:207:16)
at ExecutionContext._evaluateInternal (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:200:50)
at ExecutionContext.evaluateHandle (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:151:21)
at WaitTask.rerun (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:528:37)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9
Top Results From Across the Web
Protocol error (Runtime.callFunctionOn): Target closed. · Issue ...
I'm running into this error after 22 intervals. Node.js 8 + Puppeteer on Debian. try { await page.evaluate(async () => ( new ...
Read more >ProtocolError: Protocol error (Runtime.callFunctionOn): Target ...
I want to iterate over key-pairs of data.extractRules and get elements data from the page . This snippet inside forEach loop is causing...
Read more >Error - Target closed - Checkly
Possible causes. Obvious possible cause: the browser, context or tab is being closed at the wrong time in the script. Not-so-obvious ...
Read more >puppeteer-chat/Lobby - Gitter
For some reason the page opens but doesn't execute the code within. ... { Error: Protocol error (Runtime.callFunctionOn): Target closed.
Read more >Protocol error (Runtime.callFunctionOn): Object is not ...
This is from Puppeteer unit tests like 'window.open should use parent tab context' in browsercontext.spec.js. Overall I can see it 16 times in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@marr omitted
awaitis important for the issue. It is simplified version of:When it is required to wait at least one element from set of elements.
@marr still has a good point, in that you need know that each of those race operations are complete before closing the page out from under them.
Consider this:
It might also be possible to put a catch on each of your operations, so that their failure doesn’t cause an error in your scripting: