Events
close
Emitted when the worker is closed.console
Emitted when JavaScript within the worker callsconsole.log or other console API methods.
You need to subscribe to the ‘console’ event before the worker sends any console messages.
Methods
url
Returns the URL of the worker. Returns:string - Worker URL
evaluate
Evaluates a function in the worker context.function
required
Function to be evaluated in the worker context
any
Optional argument to pass to the function
Promise<R> - Promise that resolves to the return value
evaluateHandle
Evaluates a function in the worker context and returns a JSHandle.function
required
Function to be evaluated
any
Optional argument to pass to the function
Promise<JSHandle> - Promise that resolves to a JSHandle
waitForEvent
Waits for an event to fire and returns its value.string
required
Event name (e.g., ‘close’, ‘console’)
object
Optional waiting parameters
Promise<any> - Promise that resolves to the event data
Examples
Monitoring worker creation
Communicating with workers
Testing Service Workers
Accessing worker from page
Best practices
Related
- Page.workers() - Get all workers for a page
- BrowserContext.serviceWorkers() - Get service workers
- Page.waitForEvent(‘worker’) - Wait for worker creation
- ConsoleMessage - Console message from worker
