本文整理汇总了TypeScript中puppeteer.Browser.close方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Browser.close方法的具体用法?TypeScript Browser.close怎么用?TypeScript Browser.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类puppeteer.Browser
的用法示例。
在下文中一共展示了Browser.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: init
public async init(): Promise<void> {
log.verbose('PuppetPuppeteerBridge', 'init()')
this.state.on('pending')
try {
this.browser = await this.initBrowser()
log.verbose('PuppetPuppeteerBridge', 'init() initBrowser() done')
this.on('load', this.onLoad.bind(this))
const ready = new Promise(resolve => this.once('ready', resolve))
this.page = await this.initPage(this.browser)
await ready
this.state.on(true)
log.verbose('PuppetPuppeteerBridge', 'init() initPage() done')
} catch (e) {
log.error('PuppetPuppeteerBridge', 'init() exception: %s', e)
this.state.off(true)
try {
if (this.page) {
await this.page.close()
}
if (this.browser) {
await this.browser.close()
}
} catch (e2) {
log.error('PuppetPuppeteerBridge', 'init() exception %s, close page/browser exception %s', e, e2)
}
this.emit('error', e)
throw e
}
}
示例2: quit
public async quit(): Promise<void> {
log.verbose('PuppetPuppeteerBridge', 'quit()')
if (!this.page) {
throw new Error('no page')
}
if (!this.browser) {
throw new Error('no browser')
}
this.state.off('pending')
try {
await this.page.close()
log.silly('PuppetPuppeteerBridge', 'quit() page.close()-ed')
} catch (e) {
log.warn('PuppetPuppeteerBridge', 'quit() page.close() exception: %s', e)
}
try {
await this.browser.close()
log.silly('PuppetPuppeteerBridge', 'quit() browser.close()-ed')
} catch (e) {
log.warn('PuppetPuppeteerBridge', 'quit() browser.close() exception: %s', e)
}
this.state.off(true)
}
示例3: afterAll
afterAll(async () => {
await browser.close();
app.kill();
});