Answer the question
In order to leave comments, you need to log in
Puppeteer parallelism with Express Router Node JS. How to pass page between routes while maintaining concurrency?
app.post('/api/auth/check', async (req, res) => {
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
'https://www.google.com'
);
res.json({message: 'Success'})
} catch (e) {
console.log(e);
res.status(500).json({ message: 'Error' });
}});
app.post('/api/auth/register', async (req, res) => {
console.log('register');
// Сюда нужно передать текущую сессию пользователя (page и browser) и далее выполнять действия на той-же странице.
await page.waitForTimeout(1000);
await browser.close();
}});
Answer the question
In order to leave comments, you need to log in
Everything turned out to be easier. Made a binding to the session by creating a hash.
var createHash = require('hash-generator');
let session = createHash(12);
And then I set the variables in the post requests themselves, which will be used in the routes.
//set variable
app.set(`login_${session}`, user_login);
//call it in other routes
app.get(`login_${session}`);
I pass the session variable through react to each route, and thus everything works
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question