So I got a basic puppeteer script working that does some basic stuff: Which looks like this -
import puppeteer from "puppeteer-extra";
import RecaptchaPlugin from "puppeteer-extra-plugin-recaptcha";
import { executablePath } from "puppeteer";
import { anonymizeProxy } from "proxy-chain";
async function main() {
console.log("Starting ...");
const proxy =
"http://XXXXXXXXXXXXXXXXXXXXXX";
const newProxyUrl = await anonymizeProxy(proxy);
puppeteer.use(
RecaptchaPlugin({
provider: {
id: "2captcha",
token: "XXXXXXXXXXXXXXXXXX",
},
})
);
// Puppeteer usage as normal (headless is "false" just for this demo)
const browser = await puppeteer.launch({
headless: true,
executablePath: executablePath(),
args: [
"--single-process",
"--no-zygote",
"--no-sandbox",
`--proxy-server=${newProxyUrl}`,
],
});
try {
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(180000);
await page.goto("http://www.example.com");
// do more things etc etc
console.log("Closing the page");
await page.close();
console.log("Closed the page");
await browser.close();
console.log("Closed the browser");
await browser.process()?.kill();
console.log("Force closed the browser");
} catch (error) {
console.log(error);
} finally {
await browser.close();
}
}
main();
Now I would assume that if I started this as a node file then I would assume the node app to exit out after the console logs - "Force closed the browser" but that does not happen - it keeps running indefinitely in the terminal. Any idea how to fix this? I have already tried all the solutions in this stackoverflow and nothing seems to be helping - Puppeteer doesn't close browser