puppeteer: Error: Protocol error (Runtime.callFunctionOn): Target closed.
I’m running into this error after 22 intervals.
- Node.js 8 + Puppeteer on Debian.
try {
await page.evaluate(async () => (
new Promise((resolve, reject) => {
try {
const maxScroll = Number.MAX_SAFE_INTEGER;
let lastScroll = 0;
const interval = setInterval(() => {
window.scrollBy(0, document.body.offsetHeight);
const { scrollTop } = document.documentElement;
if (scrollTop === maxScroll || scrollTop === lastScroll) {
clearInterval(interval);
resolve();
} else {
lastScroll = scrollTop;
}
}, 1000);
} catch (error) {
reject(error);
}
})
));
} catch (error) {
log('Error while scrolling:', error);
}
log('Scrolling finished');
To reproduce it, just open a SPA that has lazy loading when scrolled to the end of the page.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 12
- Comments: 23 (9 by maintainers)
Just to make @aslushnikov’s comment more explicit, with an example right here, I found that adding the
--disable-dev-shm-usage
launch option made a massive difference:See also here.
In my case, it was because I carelessly put
await browser.close();
aboveawait page.close();
so
--shm-size=1gb
should solve your issue?In my case, I am opening same URL, in 12 tabs(browser.newPage() ), and in each tab, there is 1 api which gives huge JSON response. In this case, I am getting
Error: Protocol error (Runtime.callFunctionOn): Target closed
. To avoid this, I set--shm-size=3gb
, which helps to increase pptr browser memory. Working fine now.@FlorinAlexandru check out docs/troubleshooting.md
Turning OFF
slowMo
works for me.@andy2046 I have the same error. I’m on windows 10, node version 8.9.3. Can you please help me with some hints regarding how to set the parameter --shm-size?
can you try to add catch for the Promise, as shown below, you also need to try catch and reject inside setInterval
@andy2046 I’d be happy to look into this if you share full script with a URL.