开发者

How to Keep a puppeteer instance in NextJS server

开发者 https://www.devze.com 2022-12-07 19:13 出处:网络
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

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:

  1. Is there any other better way to keep this instance of puppeteer?
  2. 开发者_StackOverflow社区
  3. if using globle to track the instance, How can I detect hot reload? I using module.hot.accept but get: "accept is undefined.
0

精彩评论

暂无评论...
验证码 换一张
取 消