Skip to main content
Monitor page events including HTTP requests, navigation, DOM changes, and custom events emitted by the page.

Methods

page.on()

Listens for page events. Returns an AbortController for cleanup.
Parameters:
  • event: Event type to listen for
  • handler: Function to handle the event
Returns: Promise<AbortController> - Controller for stopping the listener Example:

page.once()

Listens for a page event once, then automatically removes the listener.
Parameters:
  • event: Event type to listen for
  • handler: Function to handle the event
Returns: Promise<AbortController> - Controller (listener auto-removed after first event) Example:

page.off()

Stops listening to events by providing the AbortController.
Parameters:
  • controller: AbortController returned from on() or once()
Example:

Available events

xhr

Emitted when an HTTP request (fetch/XHR) is made. Event data:
Example:

started

Emitted when page load starts. Example:

finished

Emitted when page load finishes. Example:

locationchange

Emitted when the page URL changes. Example:

domchange

Emitted when the DOM is mutated. Example:

dispatch

Emitted for custom events dispatched by the page. Example:

close

Emitted when the browser requests to close (e.g., user clicks close). Example:

closed

Emitted when the page is actually closed. Example:

hostblocked

Emitted when a host is blocked by an allowlist. Example:

Complete examples

Monitor all HTTP requests

Filter API requests

Track page lifecycle

Count DOM changes

Wait for specific request

Detect failed requests

Monitor page navigation

Measure request performance

Handle custom events

Cleanup on page close

Debug mode logging

Best practices

Always remove event listeners when done:
Use once() for events you only need to handle once:
Filter events in your handler to avoid processing irrelevant data:
Event handlers can be async, but they don’t block the page:

Waiting

Wait for specific requests

Requests

Make HTTP requests

JavaScript

Execute JavaScript

Page overview

Back to Page API overview