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.onWorker(worker -> {
System.out.println("Worker created: " + worker.url());
worker.onClose(worker1 -> System.out.println("Worker destroyed: " + worker1.url()));
});
System.out.println("Current workers:");
for (Worker worker : page.workers())
System.out.println(" " + worker.url());
Methods evaluateAdded before v1.9 worker.evaluate
Returns the return value of expression.
If the function passed to the Worker.evaluate() returns a Promise, then Worker.evaluate() would wait for the promise to resolve and return its value.
If the function passed to the Worker.evaluate() returns a non-Serializable value, then Worker.evaluate() returns undefined
. Playwright also supports transferring some additional values that are not serializable by JSON
: -0
, NaN
, Infinity
, -Infinity
.
Usage
Worker.evaluate(expression);
Worker.evaluate(expression, arg);
Arguments
JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
arg
EvaluationArgument (optional)#
Optional argument to pass to expression.
Returns
evaluateHandleAdded before v1.9 worker.evaluateHandleReturns the return value of expression as a JSHandle.
The only difference between Worker.evaluate() and Worker.evaluateHandle() is that Worker.evaluateHandle() returns JSHandle.
If the function passed to the Worker.evaluateHandle() returns a Promise, then Worker.evaluateHandle() would wait for the promise to resolve and return its value.
Usage
Worker.evaluateHandle(expression);
Worker.evaluateHandle(expression, arg);
Arguments
JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
arg
EvaluationArgument (optional)#
Optional argument to pass to expression.
Returns
urlAdded before v1.9 worker.urlUsage
Returns
waitForCloseAdded in: v1.10 worker.waitForClosePerforms action and waits for the Worker to close.
Usage
Worker.waitForClose(callback);
Worker.waitForClose(callback, options);
Arguments
options
Worker.WaitForCloseOptions
(optional)
setTimeout
double (optional) Added in: v1.9#
Maximum time to wait for in milliseconds. Defaults to 30000
(30 seconds). Pass 0
to disable timeout. The default value can be changed by using the BrowserContext.setDefaultTimeout().
callback
Runnable Added in: v1.9#
Callback that performs the action triggering the event.
Returns
Events onClose(handler)Added before v1.9 worker.onClose(handler)Emitted when this dedicated WebWorker is terminated.
Usage
Event data
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4