Inheritance
Extends:ChannelOwner
Implements: EventEmitter
Events
page: Emitted when a new page is createdclose: Emitted when context is closedrequest: Emitted when a request is maderesponse: Emitted when a response is receivedrequestfailed: Emitted when a request failsrequestfinished: Emitted when a request finishesconsole: Emitted when console message is loggeddialog: Emitted when a dialog appearsweberror: Emitted when uncaught exception occursserviceworker: Emitted when service worker is created
Properties
request
API request context for making HTTP requests.
tracing
Tracing instance for recording traces.
clock
Clock instance for controlling time.
Methods
browser
Returns the browser that owns this context.Browser | null - Parent browser or null for persistent contexts
pages
Returns all open pages in this context.Page[] - Array of pages
newPage
Creates a new page in this context.Promise<Page> - New page
cookies
Returns cookies.URL(s) to get cookies for. If not specified, returns all cookies.
Promise<Cookie[]> - Array of cookies
addCookies
Adds cookies to the context.Array of cookie objects to addEach cookie should have:
name(string): Cookie namevalue(string): Cookie valueurlordomain(string): Cookie domainpath(string, optional): Cookie pathexpires(number, optional): Expiration timestamphttpOnly(boolean, optional): HTTP only flagsecure(boolean, optional): Secure flagsameSite(‘Strict’ | ‘Lax’ | ‘None’, optional): SameSite attribute
Promise<void>
clearCookies
Clears cookies.Cookie filter options
name(string | RegExp): Cookie name or patterndomain(string | RegExp): Cookie domain or patternpath(string | RegExp): Cookie path or pattern
Promise<void>
setDefaultNavigationTimeout
Sets default navigation timeout.Timeout in milliseconds (0 to disable)
setDefaultTimeout
Sets default timeout for all operations.Timeout in milliseconds (0 to disable)
grantPermissions
Grants specified permissions.Permissions to grant (e.g., ‘geolocation’, ‘notifications’)
origin(string): Origin to grant permissions to
Promise<void>
clearPermissions
Clears all granted permissions.Promise<void>
setGeolocation
Sets geolocation.Geolocation coordinates or null to clear
latitude(number): Latitudelongitude(number): Longitudeaccuracy(number, optional): Accuracy in meters
Promise<void>
setExtraHTTPHeaders
Sets extra HTTP headers.HTTP headers object
Promise<void>
setOffline
Sets offline mode.Whether to enable offline mode
Promise<void>
setHTTPCredentials
Sets HTTP credentials for authentication.Credentials or null to clear
username(string): Usernamepassword(string): Password
Promise<void>
addInitScript
Adds a script to evaluate in every page.Script to evaluate
Argument to pass to the script
Promise<void>
exposeBinding
Exposes a binding.Binding name
Callback function
handle(boolean): Pass JSHandle instead of value
Promise<void>
exposeFunction
Exposes a function.Function name
Function to expose
Promise<void>
route
Routes matching URLs to a handler.URL pattern to match
Route handler function
times(number): Maximum number of times to handle
Promise<void>
unroute
Removes a route.URL pattern
Handler to remove (removes all if not specified)
Promise<void>
unrouteAll
Removes all routes.behavior(string): How to handle pending routes
Promise<void>
routeFromHAR
Routes requests from a HAR file.Path to HAR file
HAR routing options
url(string | RegExp): URL pattern to matchnotFound(‘abort’ | ‘fallback’): Action when request not foundupdate(boolean): Update HAR file with new requests
Promise<void>
storageState
Returns storage state.path(string): File path to save storage state to
Promise<StorageState> - Storage state object
waitForEvent
Waits for an event.Event name
Options or predicate function
Promise<any> - Event data
close
Closes the context.reason(string): Close reason
Promise<void>
newCDPSession
Creates a CDP session.Page or frame to attach to
Promise<CDPSession> - CDP session
serviceWorkers
Returns all service workers.Worker[] - Array of service workers
