1 if (!this.browser) {
2 this.browser = await puppeteer.launch(this.OPT)
3 const pages: puppeteer.Page[] = await this.browser.pages()
4
5 // close chromium by catching 'targetdestryed'
6 this.browser.on('targetdestroyed', async () => {
7 if (this.browser) {
8 const pages: puppeteer.Page[] = await this.browser.pages()
9 if (pages.length === 0) {
10 process.exit(0)
11 }
12 }
13 })
14 }
15