'How can I combine puppeteer-extra with express?
I'm trying to combine puppeter-extra with express. For each request I will be able to load a different plugin, for example:
const puppeteer = require("puppeteer-extra");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
const router = express.Router();
router.get("/", async (req, res) => {
const { useStealth } = req.query
if(useStealth) puppeteer.use(StealthPlugin());
const browser = await puppeteer.launch(parameters..)
const page = await browser.newPage();
})
The problem is that, when I send the first request with query useStealth, it will set in node cache puppeteer-extra to use StealthPlugin, so the others next requests will use it. I tried to solve this problem by clear node cache, it works but it's a problem for concorrent requests. My code to try to solve it (But it has the concorrent request problem):
delete require.cache[require.resolve('puppeteer-extra')];
puppeteer = require('puppeteer-extra');
Is there anyway to clean puppeteer.use function ? (So, It would be a new instance of puppeteer-extra per request)
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
