How to Keep a puppeteer instance in NextJS server
I'm using puppeteer in a NextJS server module and Only one instance of the puppeteer Browser (also with login information and some states from some puppeteer pages) is needed. I use globle.myBrowser
to keep this instance.(because I don't need a database, so I can't store it in a database), if I don't keep it with globle.myBrowser
, NextJs will load this module more than once, so I can't keep the state.
It's all good until when I modify this module, hot reload will not work, because global.myBrowser
will still point to the old module and new module will not working.
My questions are:
- Is there any other better way to keep this instance of puppeteer? 开发者_StackOverflow社区
- if using globle to track the instance, How can I detect hot reload? I using
module.hot.accept
but get: "accept is undefined.
精彩评论