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.
- worker.on("close")
- worker.evaluate(expression, **kwargs)
- worker.evaluate_handle(expression, **kwargs)
- worker.url
worker.on("close")#
- type: <Worker>
Emitted when this dedicated WebWorker is terminated.
worker.evaluate(expression, **kwargs)#
expression<str> JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression.arg<[EvaluationArgument]> Optional argument to pass toexpression.- returns: <Serializable>
Returns the return value of expression.
If the function passed to the worker.evaluate(expression, **kwargs) returns a Promise, then worker.evaluate(expression, **kwargs) would wait for the promise to resolve and return its value.
If the function passed to the worker.evaluate(expression, **kwargs) returns a non-Serializable value, then worker.evaluate(expression, **kwargs) returns undefined. Playwright also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity.
worker.evaluate_handle(expression, **kwargs)#
expression<str> JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted as a function. Otherwise, evaluated as an expression.arg<[EvaluationArgument]> Optional argument to pass toexpression.- returns: <JSHandle>
Returns the return value of expression as a JSHandle.
The only difference between worker.evaluate(expression, **kwargs) and worker.evaluate_handle(expression, **kwargs) is that worker.evaluate_handle(expression, **kwargs) returns JSHandle.
If the function passed to the worker.evaluate_handle(expression, **kwargs) returns a Promise, then worker.evaluate_handle(expression, **kwargs) would wait for the promise to resolve and return its value.
worker.url#
- returns: <str>