new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

worker/methods

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Worker.waitForEvent example Python sync

Example of Worker.waitForEvent in Python sync: ```python with worker.expect_event("console") as event_info: worker.evaluate("console.log(42)") message = event_info.value ``` This example uses the expect_event alias with the synchronous context manager.

Worker.evaluate method

Worker.evaluate is an async method that evaluates JavaScript code within the worker context and returns the return value of the expression as a Serializable type. It accepts an expression (string or function) and an optional argument of type EvaluationArgument. If the function returns a Promise, the method waits for the promise to resolve. If the function returns a non-Serializable value, the method returns undefined. Playwright supports transferring -0, NaN, Infinity, and -Infinity.

Worker.evaluateHandle method

Worker.evaluateHandle is an async method that evaluates JavaScript code within the worker context and returns the return value of the expression as a JSHandle. It accepts an expression (string or function) and an optional argument of type EvaluationArgument. If the function returns a Promise, the method waits for the promise to resolve. The only difference between Worker.evaluate and Worker.evaluateHandle is that Worker.evaluateHandle returns JSHandle.

Worker.url method

Worker.url is a synchronous method that returns a string representing the URL of the worker.

Worker.waitForClose method

Worker.waitForClose is an async method available in Java that performs an action and waits for the Worker to close. It returns a Worker object. It accepts options: timeout (maximum time to wait in milliseconds, defaults to 0 - no timeout) and signal (AbortSignal), and a callback parameter.

Worker.waitForConsoleMessage method

Worker.waitForConsoleMessage is an async method available in Java that waits for a console message to be emitted by the worker and returns the ConsoleMessage object. It accepts options: predicate (a function that receives ConsoleMessage and returns boolean), timeout (maximum time to wait in milliseconds, defaults to 0 - no timeout), signal (AbortSignal), and a callback parameter.

Worker.waitForEvent method for JavaScript and Python

Worker.waitForEvent is an async method in JavaScript and Python that waits for an event to fire and passes its value into a predicate function. Returns when the predicate returns truthy value. In Python it is aliased as expect_event and returns an EventContextManager. The method accepts an event parameter (string name of the event) and optionsOrPredicate (either a function or an object with predicate and timeout options). It throws an error if the page is closed before the event is fired and returns the event data value.

Worker.waitForEvent optionsOrPredicate parameter

The optionsOrPredicate parameter in Worker.waitForEvent accepts either a function or an object. As an object it contains: predicate (function that receives event data and resolves to truthy value when waiting should resolve) and timeout (optional float in milliseconds, defaults to 0 - no timeout; the default can be changed via actionTimeout option in config or by using BrowserContext.setDefaultTimeout or Page.setDefaultTimeout methods).

Worker.waitForEvent example JavaScript

Example of Worker.waitForEvent in JavaScript: ```js const consolePromise = worker.waitForEvent('console'); await worker.evaluate('console.log(42)'); const consoleMessage = await consolePromise; ``` This example starts waiting for a console event without awaiting, then evaluates code that logs to console, and finally waits for and receives the console message.

Give your agent this brain