Interface Worker

The Worker class represents a WebWorker. worker event is emitted on the page object to signal a worker creation. close event is emitted on the worker object when the worker is gone.

page.on('worker', worker => {
console.log('Worker created: ' + worker.url());
worker.on('close', worker => console.log('Worker destroyed: ' + worker.url()));
});

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

Hierarchy

  • Worker

Methods

  • Emitted when this dedicated WebWorker is terminated.

    Parameters

    • event: "close"
    • listener: ((worker) => any)
        • (worker): any
        • Parameters

          Returns any

    Returns Worker

  • Returns the return value of pageFunction.

    If the function passed to the worker.evaluate(pageFunction[, arg]) returns a [Promise], then worker.evaluate(pageFunction[, arg]) would wait for the promise to resolve and return its value.

    If the function passed to the worker.evaluate(pageFunction[, arg]) returns a non-[Serializable] value, then worker.evaluate(pageFunction[, arg]) returns undefined. Playwright also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity.

    Type Parameters

    • R

    • Arg

    Parameters

    • pageFunction: PageFunction<Arg, R>

      Function to be evaluated in the worker context.

    • arg: Arg

      Optional argument to pass to pageFunction.

    Returns Promise<R>

  • Returns the return value of pageFunction.

    If the function passed to the worker.evaluate(pageFunction[, arg]) returns a [Promise], then worker.evaluate(pageFunction[, arg]) would wait for the promise to resolve and return its value.

    If the function passed to the worker.evaluate(pageFunction[, arg]) returns a non-[Serializable] value, then worker.evaluate(pageFunction[, arg]) returns undefined. Playwright also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity.

    Type Parameters

    • R

    Parameters

    • pageFunction: PageFunction<void, R>

      Function to be evaluated in the worker context.

    • Optional arg: any

      Optional argument to pass to pageFunction.

      Optional

    Returns Promise<R>

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "close"
    • listener: ((worker) => any)
        • (worker): any
        • Parameters

          Returns any

    Returns Worker

  • Emitted when this dedicated WebWorker is terminated.

    Parameters

    • event: "close"
    • listener: ((worker) => any)
        • (worker): any
        • Parameters

          Returns any

    Returns Worker

  • Adds an event listener that will be automatically removed after it is triggered once. See addListener for more information about this event.

    Parameters

    • event: "close"
    • listener: ((worker) => any)
        • (worker): any
        • Parameters

          Returns any

    Returns Worker

  • Emitted when this dedicated WebWorker is terminated.

    Parameters

    • event: "close"
    • listener: ((worker) => any)
        • (worker): any
        • Parameters

          Returns any

    Returns Worker

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "close"
    • listener: ((worker) => any)
        • (worker): any
        • Parameters

          Returns any

    Returns Worker

  • Returns string

Generated using TypeDoc