Event

Enum Event 

Source
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 acceptDownloads set to true when user needs access to the downloaded content. If acceptDownloads is 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)

§

FrameNavigated(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.

§

WebSocket(WebSocket)

§

Worker(Worker)

§

Video(Video)

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<Evt> for Event

Source§

fn from(e: Evt) -> Event

Converts to this type from the input type.
Source§

impl IsEvent for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.