目前正在开发一个小型 NodeJS 项目,其中涉及 Puppeteer 库。我遇到的问题是 index.js 中的 main() 函数似乎永远不会退出。所有代码都运行良好,但在 VS code 中看起来程序仍在运行。
下面是一些示例代码:
var UserAgent = require('user-agents');
const userAgent = new UserAgent();
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
class TS {
constructor() {
let page;
}
async init() {
const browser = await puppeteer.launch({ headless: false });
this.page = await browser.newPage();
await this.page.setUserAgent(userAgent.toString());
}
}
async function main(params) {
console.log("Started main..");
const ts = new TS();
await ts.init();
console.log("Ending main..");
}
main().catch(e => console.error(e));;
Run Code Online (Sandbox Code Playgroud)
如果我在 VS code …
javascript program-entry-point asynchronous node.js puppeteer