本文整理汇总了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
}
示例2: beforeEach
beforeEach(async () => {
page = await browser.newPage();
page.on('dialog', async (dialog) => {
await dialog.dismiss();
});
errors = errorWatcher(page);
});
示例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;
};