I have a Node.js script that uses puppeteer and repeats a task constantly. After a random number of repetitions the following error appears and the program crashes:
C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:28
throw new Error(message);
^
Error: We either navigate top level or have old version of the navigated frame
at assert (C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:28:15)
at FrameManager._FrameManager_onFrameNavigated (C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:343:28)
at C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:94:104
at C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\vendor\mitt\src\index.js:51:68
at Array.map (<anonymous>)
at Object.emit (C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\vendor\mitt\src\index.js:51:43)
at CDPSession.emit (C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\common\EventEmitter.js:72:22)
at CDPSession._onMessage (C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:299:18)
at Connection.onMessage (C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:155:25)
at WebSocket.<anonymous> (C:\Users\ben_s\Desktop\nike\node_modules\puppeteer\lib\cjs\puppeteer\node\NodeWebSocketTransport.js:47:32)
I have not been able to find a solution online despite seeing a couple of discussions regarding it. I would simply try and catch the error but I am unsure how to do that when the error is being thrown in some file within the puppeteer lib
folder. Even doing a try catch of the entire script does not pick it up. Any advice on how to deal with this appreciated.
I am unable to find a way to reproduce this. It is running on a Windows 2022 Datacenter server.
I have used the following to catch the error which stops the program from crashing but does not stop the error from occurring:
An alternative solution could include a way to catch the error that is thrown outside the main code files. I have done this by including the following:
process.on('uncaughtException', (e) => {
console.log("uncaughtException:", e);
})
This allows the program to continue as normal which should work for now