pub enum Event {
Show 19 variants
Close,
Crash,
Console(ConsoleMessage),
Dialog,
DomContentLoaded,
Download(Download),
FrameAttached(Frame),
FrameDetached(Frame),
FrameNavigated(Frame),
Load,
PageError,
Popup(Page),
Request(Request),
RequestFailed(Request),
RequestFinished(Request),
Response(Response),
WebSocket(WebSocket),
Worker(Worker),
Video(Video),
}Variants§
Close
Crash
Console(ConsoleMessage)
Emitted when JavaScript within the page calls one of console API methods, e.g. console.log or console.dir. Also
emitted if the page throws an error or a warning.
The arguments passed into console.log appear as arguments on the event handler.
An example of handling console event:
page.on('console', async msg => {
for (let i = 0; i < msg.args().length; ++i)
console.log(`${i}: ${await msg.args()[i].jsonValue()}`);
});
await page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));Dialog
Emitted when a JavaScript dialog appears, such as alert, prompt, confirm or beforeunload. Listener must
either [method: Dialog.accept] or [method: Dialog.dismiss] the dialog - otherwise the page will
freeze waiting for the dialog, and
actions like click will never finish.
NOTE: When no [
event: Page.dialog] listeners are present, all dialogs are automatically dismissed.
DomContentLoaded
Download(Download)
Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
Download instance.
NOTE: Browser context must be created with the
acceptDownloadsset totruewhen user needs access to the downloaded content. IfacceptDownloadsis not set, download events are emitted, but the actual download is not performed and user has no access to the downloaded files.
FrameAttached(Frame)
Emitted when a file chooser is supposed to appear, such as after clicking the <input type=file>. Playwright can
respond to it via setting the input files using [method: FileChooser.setFiles] that can be uploaded after that.
page.on('filechooser', async (fileChooser) => {
await fileChooser.setFiles('/tmp/myfile.pdf');
});FrameDetached(Frame)
Load
PageError
Popup(Page)
Emitted when the page opens a new tab or window. This event is emitted in addition to the
[event: BrowserContext.page], but only for popups relevant to this page.
The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
popup with window.open('http://example.com'), this event will fire when the network request to http://example.com is
done and its response has started loading in the popup.
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.evaluate(() => window.open('https://example.com')),
]);
console.log(await popup.evaluate('location.href'));NOTE: Use [
method: Page.waitForLoadState] to wait until the page gets to a particular state (you should not need it in most cases).
Request(Request)
Emitted when a page issues a request. The request object is read-only. In order to intercept and mutate requests, see
[method: Page.route] or [method: BrowserContext.route].
RequestFailed(Request)
Emitted when a request fails, for example by timing out.
NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with [
event: Page.requestFinished] event and not with [event: Page.requestFailed].
RequestFinished(Request)
Emitted when a request finishes successfully after downloading the response body. For a successful response, the
sequence of events is request, response and requestfinished.
Response(Response)
Emitted when response status and headers are received for a request. For a successful response, the sequence of events
is request, response and requestfinished.