3

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

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Ben S.
  • 111
  • 1
  • 8
  • Can you provide the smallest runnable amount of code that reproduces the error? Environment details are also useful. See [mcve] for guidance. Thanks. – ggorlen Jul 25 '22 at 01:49
  • Related: [#3309](https://github.com/puppeteer/puppeteer/issues/3309) and [#7050](https://github.com/puppeteer/puppeteer/issues/7050) – ggorlen Jul 25 '22 at 02:43
  • updated with as much info as I can offer. Apologies it is not much as there is no pattern to when it appears. – Ben S. Jul 26 '22 at 19:35
  • Thanks, but I still don't see any code here I can run. Just because the error is thrown by Puppeteer doesn't mean it's not your code's fault (in fact, it probably is). I've seen this error intermittently in my code, and as I recall it was a typical race condition or mistake, but I can't remember what I was doing to cause it (this is why I like to answer these sort of questions--future self thanks me). – ggorlen Jul 26 '22 at 19:39
  • Someone else posted a site and script that reproduces the issue in [puppeteer Error Unknown key: " " when trying to press space key](https://stackoverflow.com/questions/73140190/puppeteer-error-unknown-key-when-trying-to-press-space-key) – ggorlen Jul 27 '22 at 18:37

0 Answers0