Skip to main content
Version: Next

WebWorker class

This class represents a WebWorker.

Signature:

export declare abstract class WebWorker extends EventEmitter<Record<EventType, unknown>>

Extends: EventEmitter<Record<EventType, unknown>>

Remarks

The events workercreated and workerdestroyed are emitted on the page object to signal the worker lifecycle.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the WebWorker class.

Example

page.on('workercreated', worker =>
console.log('Worker created: ' + worker.url())
);
page.on('workerdestroyed', worker =>
console.log('Worker destroyed: ' + worker.url())
);

console.log('Current workers:');
for (const worker of page.workers()) {
console.log(' ' + worker.url());
}

Properties

PropertyModifiersTypeDescription
clientreadonlyCDPSessionThe CDP session client the WebWorker belongs to.

Methods

MethodModifiersDescription
evaluateEvaluates a given function in the worker.
evaluateHandleEvaluates a given function in the worker.
urlThe URL of this web worker.