I am using puppeteer and express js to make an api. I have done my code stuff and now i am testing the api on postman but i have a problem which is i could not send multiple scripts at once i mean i can send but just returning the last one.So what is the problem.
const express = require("express");
const app = express();
app.use(express.json())
const puppeteer = require("puppeteer");
const port = 3000;
let browser = null;
var target_url = ""
app.post('/get/script_result', async (req, res) => {
if (browser == null) browser = await puppeteer.launch({
headless: false, defaultViewport: null, args: ['--disable-infobars', '--disable-notifications', '--disable-default-apps',
'--no-sandbox', '--mute-audio', '--ignore-certificate-errors', '--disable-features=LookalikeUrlNavigationSuggestionsUI'], ignoreHTTPSErrors: true
});
try {
var page = await browser.newPage()
await page.goto(req.body.target_url);
var script = ""
var script_delay = ""
await page.waitForTimeout(`${req.body.script_delay}`)
const handle = await page.evaluate(`${req.body.script}`)
res.send(handle)
res.end()
//await page.close();
return res.status(200)
}
catch (e) {
console.log(e);
res.send(e)
res.status(500)
}
})
app.listen(port, () => {
console.log(`app is running on port: ${port}`);
});