本文整理匯總了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();
});