當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Page.close方法代碼示例

本文整理匯總了TypeScript中puppeteer.Page.close方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Page.close方法的具體用法?TypeScript Page.close怎麽用?TypeScript Page.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在puppeteer.Page的用法示例。


在下文中一共展示了Page.close方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
    }
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:35,代碼來源:bridge.ts

示例2: onLoad

  public async onLoad(page: Page): Promise<void> {
    log.verbose('PuppetPuppeteerBridge', 'initPage() on(load) %s', page.url())

    if (this.state.off()) {
      log.verbose('PuppetPuppeteerBridge', 'initPage() onLoad() OFF state detected. NOP')
      return // reject(new Error('onLoad() OFF state detected'))
    }

    try {
      const emitExist = await page.evaluate(() => {
        return typeof window['emit'] === 'function'
      })
      if (!emitExist) {
        await page.exposeFunction('emit', this.emit.bind(this))
      }

      await this.readyAngular(page)
      await this.inject(page)
      await this.clickSwitchAccount(page)

      this.emit('ready')

    } catch (e) {
      log.error('PuppetPuppeteerBridge', 'init() initPage() onLoad() exception: %s', e)
      await page.close()
      this.emit('error', e)
    }
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:28,代碼來源:bridge.ts

示例3: 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)
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:28,代碼來源:bridge.ts

示例4: takeComponentScreenshot

function* takeComponentScreenshot() {
  const state: ApplicationState = yield select();

  yield put(componentScreenshotStarted());
  try {

    const entries = getPreviewComponentEntries(state);

    console.log(`Taking screenshot of ${entries.length} components...`);

    const clippings: ScreenshotClippings = {};
    for (const entry of entries) {
      clippings[getPreviewClippingNamespace(entry.componentId, entry.previewName)] = entry.bounds;
    }

    const previewUrl = getAllComponentsPreviewUrl(state)
    const browser = state.headlessBrowser;
    const page: Page = yield call(browser.newPage.bind(browser));
    yield call(page.goto.bind(page), previewUrl);
    yield call(page.setViewport.bind(page), getAllComponentsPreviewSize(entries));

    // wait for a bit for all resources to load
    yield call(page.waitForSelector.bind(page), ".__ready");

    const buffer = yield call(page.screenshot.bind(page, { type: "png" }));
    yield put(componentScreenshotTaken(buffer, clippings, "image/png"));

    page.close();
  } catch(e) {
    console.error(e.stack);
  }
}
開發者ID:cryptobuks,項目名稱:tandem,代碼行數:32,代碼來源:screenshots.ts

示例5: afterEach

afterEach(async () => {
    await page.close();
});
開發者ID:rla,項目名稱:feeds,代碼行數:3,代碼來源:app.test.ts


注:本文中的puppeteer.Page.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。