puppeteer: [Bug]: Puppeteer throwing error when running non-headless
Bug description
I’m using puppeteer to visit a webpage and view all the network requests that fire but I’ve found that an error is thrown when running in non-headless mode and I can’t figure out the cause of this error. No amount of Googling has turned up an answer so far. Here’s the error:
/Users/myusername/dev/puppeteer-test/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226
error: new Errors_js_1.ProtocolError(),
^
ProtocolError: Protocol error (Page.createIsolatedWorld): No frame for given id found
at /Users/myusername/dev/puppeteer-test/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226:24
at new Promise (<anonymous>)
at CDPSession.send (/Users/myusername/dev/puppeteer-test/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:222:16)
at /Users/myusername/dev/puppeteer-test/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:290:37
at Array.map (<anonymous>)
at FrameManager._ensureIsolatedWorld (/Users/myusername/dev/puppeteer-test/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:290:14)
at async Promise.all (index 1)
at async FrameManager.initialize (/Users/myusername/dev/puppeteer-test/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:102:13)
at async FrameManager._onAttachedToTarget (/Users/myusername/dev/puppeteer-test/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:185:9) {
originalMessage: 'No frame for given id found'
}
This is a dumbed down sample of my project code that throws this error:
const puppeteer = require('puppeteer');
const url = 'https://jpstyle.us/';
(async () => {
const browser = await puppeteer.launch({
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
headless: false,
slowMo: 250
});
const page = await browser.newPage();
let foundRequest = false;
let request;
await page.setRequestInterception(true);
page.on('request', (interceptedRequest) => {
if (interceptedRequest.url().includes('googleads.g.doubleclick.net/pagead/ads')) {
foundRequest = true;
request = interceptedRequest;
}
interceptedRequest.continue();
});
await page.goto(url, { waitUntil: 'networkidle0' });
await browser.close();
console.log(`Google Ads Remarketing was ${foundRequest ? 'found' : 'not found'}`);
if (foundRequest) {
console.log(request);
}
})();
If you change the value of headless
to true
in the launch options object that is passed when launching puppeteer then this error goes away and everything runs as expected. For the purposes of this project I can’t run in headless mode, so I need to figure out why this error is happening.
Any help or direction is appreciated!
Puppeteer version
13.0.1
Node.js version
v16.13.1
npm version
8.1.2
What operating system are you seeing the problem on?
macOS
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 9
- Comments: 16
I have currently “fixed” this problem by adding a global error catcher:
Edit: Use this so that it ignores this specific error only
I’m also having this issue, with MacOS in Node v15.12.0. I’d love to see a solution as I have a project that can’t be headless!