9fdf2ba280
Also took the opportunity to pull out the PDF types into their own file to clear up `Page.ts` slightly and give the PDF code a more natural place to live.
7.8 KiB
7.8 KiB
Page class
Page provides methods to interact with a single tab or extension background page in Chromium.
Signature:
export declare class Page extends EventEmitter
Extends: EventEmitter
Remarks
One Browser instance might have multiple Page instances.
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the Page
class.
Example 1
This example creates a page, navigates it to a URL, and then * saves a screenshot:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'});
await browser.close();
})();
The Page class extends from Puppeteer's EventEmitter class and will emit various events which are documented in the PageEmittedEvents enum.
Example 2
This example logs a message for a single page load
event:
page.once('load', () => console.log('Page loaded!'));
To unsubscribe from events use the off
method:
function logRequest(interceptedRequest) {
console.log('A request was made:', interceptedRequest.url());
}
page.on('request', logRequest);
// Sometime later...
page.off('request', logRequest);
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
accessibility | Accessibility | ||
coverage | Coverage | ||
keyboard | Keyboard | ||
mouse | Mouse | ||
touchscreen | Touchscreen | ||
tracing | Tracing |