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


TypeScript Page.on方法代碼示例

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


在下文中一共展示了Page.on方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: initPage

  public async initPage(browser: Browser): Promise<Page> {
    log.verbose('PuppetPuppeteerBridge', 'initPage()')

    // set this in time because the following callbacks
    // might be called before initPage() return.
    const page = this.page =  await browser.newPage()

    page.on('error',  e => this.emit('error', e))

    page.on('dialog', this.onDialog.bind(this))

    const cookieList = (await this.options.profile.get('cookies')) as Cookie[]
    const url        = this.entryUrl(cookieList)

    log.verbose('PuppetPuppeteerBridge', 'initPage() before page.goto(url)')
    await page.goto(url) // Does this related to(?) the CI Error: exception: Navigation Timeout Exceeded: 30000ms exceeded
    log.verbose('PuppetPuppeteerBridge', 'initPage() after page.goto(url)')

    if (cookieList && cookieList.length) {
      await page.setCookie(...cookieList)
      log.silly('PuppetPuppeteerBridge', 'initPage() page.setCookie() %s cookies set back', cookieList.length)
    }

    page.on('load', () => this.emit('load', page))
    await page.reload() // reload page to make effect of the new cookie.

    return page
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:28,代碼來源:bridge.ts

示例2: beforeEach

beforeEach(async () => {
    page = await browser.newPage();
    page.on('dialog', async (dialog) => {
        await dialog.dismiss();
    });
    errors = errorWatcher(page);
});
開發者ID:rla,項目名稱:feeds,代碼行數:7,代碼來源:app.test.ts

示例3: Error

export const errorWatcher = (page: Page) => {
    const errors: Error[] = [];
    page.on('error', (err) => {
        errors.push(err);
    });
    page.on('pageerror', (err) => {
        errors.push(err);
    });
    page.on('requestfailed', (request) => {
        errors.push(new Error(`Request to url ${request.url()} failed.`));
    });
    page.on('requestfinished', (request) => {
        const response = request.response();
        if (response) {
            const status = response.status();
            if (status < 200 || status > 400) {
                errors.push(new Error(`Request to url ${request.url()} failed with non-200/300 status code.`));
            }
        }
    });
    return errors;
};
開發者ID:rla,項目名稱:feeds,代碼行數:22,代碼來源:testUtils.ts


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