Lifecycle
newPage
Create a new page (tab) in the browser.The new page is automatically set as the active page. Defaults to “about:blank” if no URL is provided.
The URL to navigate to in the new page.
Return value
pages
Get all open pages in the browser context.Returns an array of all open pages, ordered from oldest to newest.
Return value
close
Close the browser context and all associated pages.This method:
- Closes the CDP connection
- Cleans up all pages
- Clears all internal mappings
Other
activePage
Get the currently active page.The active page is determined by:
- Most recently interacted with page
- Most recently created page if no interaction history
- undefined if all pages have been closed
Return value
setActivePage
Set a specific page as the active page.This method:
- Marks the page as most recently used
- Brings the tab to the foreground (in headed mode)
- Makes it the default page for subsequent operations
The ID of the page to set as active.
addInitScript
Inject JavaScript that runs before any page scripts on every navigation.This method:
- Runs at document start
- Installs the script on all currently open pages
- Replays it on every navigation of those pages
- Automatically applies to any pages created after calling addInitScript()
The script to inject. Can be raw source code, a file reference, or a function.
Extra data that is JSON-serialized and passed to your function.

