public interface Worker
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());
| Modifier and Type | Interface and Description |
|---|---|
static class |
Worker.WaitForCloseOptions |
| Modifier and Type | Method and Description |
|---|---|
default Object |
evaluate(String expression)
Returns the return value of
expression. |
Object |
evaluate(String expression,
Object arg)
Returns the return value of
expression. |
default JSHandle |
evaluateHandle(String expression)
Returns the return value of
expression as a JSHandle. |
JSHandle |
evaluateHandle(String expression,
Object arg)
Returns the return value of
expression as a JSHandle. |
void |
offClose(Consumer<Worker> handler)
Removes handler that was previously added with
onClose(handler). |
void |
onClose(Consumer<Worker> handler)
Emitted when this dedicated WebWorker is
terminated.
|
String |
url() |
default Worker |
waitForClose(Runnable callback)
Performs action and waits for the Worker to close.
|
Worker |
waitForClose(Worker.WaitForCloseOptions options,
Runnable callback)
Performs action and waits for the Worker to close.
|
void offClose(Consumer<Worker> handler)
onClose(handler).default Object evaluate(String expression)
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.
expression - 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.Object evaluate(String expression, Object arg)
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.
expression - 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 - Optional argument to pass to expression.default JSHandle evaluateHandle(String expression)
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.
expression - 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.JSHandle evaluateHandle(String expression, Object arg)
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.
expression - 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 - Optional argument to pass to expression.String url()
default Worker waitForClose(Runnable callback)
callback - Callback that performs the action triggering the event.Worker waitForClose(Worker.WaitForCloseOptions options, Runnable callback)
callback - Callback that performs the action triggering the event.Copyright © 2021. All rights reserved.