Interface Worker
- All Known Implementing Classes:
WorkerImpl
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());
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault ObjectReturns the return value ofexpression.Returns the return value ofexpression.default JSHandleevaluateHandle(String expression) Returns the return value ofexpressionas aJSHandle.evaluateHandle(String expression, Object arg) Returns the return value ofexpressionas aJSHandle.voidRemoves handler that was previously added withonClose(handler).voidEmitted when this dedicated WebWorker is terminated.url()waitForClose(Worker.WaitForCloseOptions options, Runnable callback) Performs action and waits for the Worker to close.default WorkerwaitForClose(Runnable callback) Performs action and waits for the Worker to close.
-
Method Details
-
onClose
Emitted when this dedicated WebWorker is terminated. -
offClose
Removes handler that was previously added withonClose(handler). -
evaluate
Returns the return value ofexpression.If the function passed to the
Worker.evaluate()returns a Promise, thenWorker.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, thenWorker.evaluate()returnsundefined. Playwright also supports transferring some additional values that are not serializable byJSON:-0,NaN,Infinity,-Infinity.- Parameters:
expression- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.- Since:
- v1.8
-
evaluate
Returns the return value ofexpression.If the function passed to the
Worker.evaluate()returns a Promise, thenWorker.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, thenWorker.evaluate()returnsundefined. Playwright also supports transferring some additional values that are not serializable byJSON:-0,NaN,Infinity,-Infinity.- Parameters:
expression- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.arg- Optional argument to pass toexpression.- Since:
- v1.8
-
evaluateHandle
Returns the return value ofexpressionas aJSHandle.The only difference between
Worker.evaluate()andWorker.evaluateHandle()is thatWorker.evaluateHandle()returnsJSHandle.If the function passed to the
Worker.evaluateHandle()returns a Promise, thenWorker.evaluateHandle()would wait for the promise to resolve and return its value.- Parameters:
expression- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.- Since:
- v1.8
-
evaluateHandle
Returns the return value ofexpressionas aJSHandle.The only difference between
Worker.evaluate()andWorker.evaluateHandle()is thatWorker.evaluateHandle()returnsJSHandle.If the function passed to the
Worker.evaluateHandle()returns a Promise, thenWorker.evaluateHandle()would wait for the promise to resolve and return its value.- Parameters:
expression- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.arg- Optional argument to pass toexpression.- Since:
- v1.8
-
url
String url()- Since:
- v1.8
-
waitForClose
Performs action and waits for the Worker to close.- Parameters:
callback- Callback that performs the action triggering the event.- Since:
- v1.10
-
waitForClose
Performs action and waits for the Worker to close.- Parameters:
callback- Callback that performs the action triggering the event.- Since:
- v1.10
-