I'm trying to figure out a way to start and stop a puppeteer scraper from an html onclick using NodeJS Express Mongodb Mongoose. Currently my method is to create a /start route and then start the async function for Puppeteer but still no idea on how I can stop it as I'm fairly new. Any other solution would be great. Thank you in advance.
My html Button
<input class="form-check-input" type="checkbox" id="startswitch" onclick='window.location.assign("/settings/start")'>
My Backend Router for puppeteer launch
router.get('/start', function(req, res) {
const puppeteer = require('puppeteer');
const UrL = "https://www.google.co.th";
(async () => {
const browser = await puppeteer.launch({headless: false, args: ["--no-sandbox"]});
//Some Scrapings Here
//Some Scrapings Here
//Some Scrapings Here
//Some Scrapings Here
})();
});