GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Playwright for Java
  • Docs
  • API
  • Java
  • Node.js
  • Python
  • .NET
  • Community
  • Classes
  • APIRequestContext
  • APIResponse
  • Browser
  • BrowserContext
  • BrowserType

This view

  • Original page
  • New address

GeezerVison is showing playwright.dev — Worker | Playwright Java

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​

evaluate​

Added 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

  • expression String#

    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

  • Object#

evaluateHandle​

Added before v1.9 worker.evaluateHandle

Returns 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

  • expression String#

    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

  • JSHandle#

url​

Added before v1.9 worker.url

Usage

Worker.url();

Returns

  • String#

waitForClose​

Added in: v1.10 worker.waitForClose

Performs 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

  • Worker#

waitForConsoleMessage​

Added in: v1.57 worker.waitForConsoleMessage

Performs action and waits for a console message.

Usage

Worker.waitForConsoleMessage(callback);
Worker.waitForConsoleMessage(callback, options);

Arguments

  • options Worker.WaitForConsoleMessageOptions (optional)

    • setPredicate Predicate<ConsoleMessage> (optional)#

      Receives the ConsoleMessage object and resolves to true when the waiting should resolve.

    • setTimeout double (optional)#

      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#

    Callback that performs the action triggering the event.

Returns

  • ConsoleMessage#

Events​

onClose(handler)​

Added before v1.9 worker.onClose(handler)

Emitted when this dedicated WebWorker is terminated.

Usage

Worker.onClose(handler)

Event data

  • Worker

onConsole(handler)​

Added in: v1.57 worker.onConsole(handler)

Emitted when JavaScript within the worker calls one of console API methods, e.g. console.log or console.dir.

Usage

Worker.onConsole(handler)

Event data

  • ConsoleMessage
  • Methods
    • evaluate
    • evaluateHandle
    • url
    • waitForClose
    • waitForConsoleMessage
  • Events
    • onClose(handler)
    • onConsole(handler)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.