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
APIRequestContext
API request context for making HTTP requests.
tracing
Tracing
Tracing instance for recording traces.
clock
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.string | string[]
URL(s) to get cookies for. If not specified, returns all cookies.
Promise<Cookie[]> - Array of cookies
addCookies
Adds cookies to the context.Cookie[]
required
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.ClearCookiesOptions
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.number
required
Timeout in milliseconds (0 to disable)
setDefaultTimeout
Sets default timeout for all operations.number
required
Timeout in milliseconds (0 to disable)
grantPermissions
Grants specified permissions.string[]
required
Permissions to grant (e.g., ‘geolocation’, ‘notifications’)
object
origin(string): Origin to grant permissions to
Promise<void>
clearPermissions
Clears all granted permissions.Promise<void>
setGeolocation
Sets geolocation.object | null
required
Geolocation coordinates or null to clear
latitude(number): Latitudelongitude(number): Longitudeaccuracy(number, optional): Accuracy in meters
Promise<void>
setExtraHTTPHeaders
Sets extra HTTP headers.Headers
required
HTTP headers object
Promise<void>
setOffline
Sets offline mode.boolean
required
Whether to enable offline mode
Promise<void>
setHTTPCredentials
Sets HTTP credentials for authentication.object | null
required
Credentials or null to clear
username(string): Usernamepassword(string): Password
Promise<void>
addInitScript
Adds a script to evaluate in every page.Function | string | object
required
Script to evaluate
any
Argument to pass to the script
Promise<void>
exposeBinding
Exposes a binding.string
required
Binding name
Function
required
Callback function
object
handle(boolean): Pass JSHandle instead of value
Promise<void>
exposeFunction
Exposes a function.string
required
Function name
Function
required
Function to expose
Promise<void>
route
Routes matching URLs to a handler.string | RegExp
required
URL pattern to match
Function
required
Route handler function
object
times(number): Maximum number of times to handle
Promise<void>
unroute
Removes a route.string | RegExp
required
URL pattern
Function
Handler to remove (removes all if not specified)
Promise<void>
unrouteAll
Removes all routes.object
behavior(string): How to handle pending routes
Promise<void>
routeFromHAR
Routes requests from a HAR file.string
required
Path to HAR file
RouteFromHAROptions
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.object
path(string): File path to save storage state to
Promise<StorageState> - Storage state object
waitForEvent
Waits for an event.string
required
Event name
WaitForEventOptions | Function
Options or predicate function
Promise<any> - Event data
close
Closes the context.object
reason(string): Close reason
Promise<void>
newCDPSession
Creates a CDP session.Page | Frame
required
Page or frame to attach to
Promise<CDPSession> - CDP session
serviceWorkers
Returns all service workers.Worker[] - Array of service workers
