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

core page methods - navigation

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

Page.goto() navigates to URL

The goto() method is an async method that navigates the page to a specified URL.

Frame.waitForNavigation parameters and options

Frame.waitForNavigation accepts the following parameters and options: - action (optional, callback): action to perform that will cause navigation, since v1.12 - url (optional, string/RegExp/function): URL pattern to match, since v1.8 - waitUntil (optional): 'domcontentloaded', 'load', or 'networkidle', since v1.8 - timeout (optional): timeout in milliseconds, since v1.8 - signal (optional): AbortSignal to cancel waiting, since v1.8

Frame.waitForNavigation is deprecated and returns Response or null

Frame.waitForNavigation is deprecated and inherently racy; Frame.waitForURL should be used instead. It waits for frame navigation and returns the main resource response. In case of multiple redirects, the navigation resolves with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, it resolves with null.

Frame.waitForURL waits for frame to navigate to given URL

Frame.waitForURL waits for the frame to navigate to the given URL. It is useful when you run code that will indirectly cause the frame to navigate.

Frame.waitForURL parameters and options

Frame.waitForURL accepts the following parameters and options: - url (required, string/RegExp/function): URL pattern to wait for, since v1.11 - timeout (optional): timeout in milliseconds, since v1.11 - signal (optional): AbortSignal to cancel waiting, since v1.11 - waitUntil (optional): 'domcontentloaded', 'load', or 'networkidle', since v1.11

Frame.waitForURL example - waiting for navigation to target URL

This example demonstrates Frame.waitForURL: ```js await frame.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigation await frame.waitForURL('**/target.html'); ``` ```python async await frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation await frame.wait_for_url("**/target.html") ```

Frame.goto() method parameters, options and return type

Frame.goto() is an async method that returns null or Response. Parameters: url (string URL with scheme, e.g. https://). Options: waitUntil (string, 'load'/'domcontentloaded'/'networkidle'/'commit'), timeout (float/number in ms), signal (AbortSignal), referer (string, referer header value). Returns main resource response. Throws error for SSL issues, invalid URL, timeout, unreachable server, or main resource load failure. Does not throw for 404/500 status codes. Returns null only for about:blank or same URL with different hash.

Frame.url returns frame's url as string

Frame.url is a method that returns a string representing the frame's current URL.

python-csharp-java-wait-for-navigation-url

The url parameter is string, RegExp, or function(URL):boolean. Glob pattern, regex, or predicate matching navigation. String without wildcard waits for exact URL match.

navigation-timeout for Python, Java, C#

The timeout parameter is type float. Maximum operation time in milliseconds. Defaults to 30 seconds. Pass 0 to disable timeout. Default can be changed using BrowserContext.setDefaultNavigationTimeout, BrowserContext.setDefaultTimeout, Page.setDefaultNavigationTimeout, or Page.setDefaultTimeout methods.

navigation-timeout for JavaScript

The timeout parameter is type float. Maximum operation time in milliseconds. Defaults to 0 (no timeout). Default can be changed via navigationTimeout option in config, or by using BrowserContext.setDefaultNavigationTimeout, BrowserContext.setDefaultTimeout, Page.setDefaultNavigationTimeout, or Page.setDefaultTimeout methods.

navigation-wait-until: waitUntil parameter states

The waitUntil parameter accepts 'domcontentloaded', 'load', 'networkidle', or 'commit'. Default is 'load'. 'domcontentloaded' considers operation finished when DOMContentLoaded event fires. 'load' considers operation finished when load event fires. 'networkidle' is DISCOURAGED and considers operation finished when no network connections exist for at least 500ms; do not use for testing. 'commit' considers operation finished when network response is received and document starts loading.

Page.goBack - navigate to previous page

Page.goBack() is an async method (since v1.8, returns null|Response) that navigates to the previous page in history, returning the main resource response. If there are multiple redirects, it resolves with the response of the last redirect. Returns null if navigation cannot go back. Options: waitUntil (LoadState - 'load'|'domcontentloaded'|'networkidle', since v1.8), timeout (number, since v1.8), signal (AbortSignal). Note: Back/Forward Cache (BFCache) testing is not supported; Playwright disables BFCache by default.

Page.goForward - navigate to next page

Page.goForward() is an async method (since v1.8, returns null|Response) that navigates to the next page in history, returning the main resource response. If there are multiple redirects, it resolves with the response of the last redirect. Returns null if navigation cannot go forward. Options: waitUntil (LoadState, since v1.8), timeout (number, since v1.8), signal (AbortSignal). Note: Back/Forward Cache (BFCache) testing is not supported.

Page.goto - navigate to URL

Page.goto() is an async method (since v1.8, alias-java: navigate, returns null|Response) that navigates to a URL and returns the main resource response. In case of multiple redirects, returns the first non-redirect response. Accepts: url (string, must include scheme like https://). Options: waitUntil (LoadState, since v1.8), timeout (number, since v1.8), signal (AbortSignal), referer (string, since v1.8 - referer header value). The method will throw on SSL errors, invalid URLs, timeout, unreachable servers, or main resource load failure. It will not throw on valid HTTP status codes (404, 500, etc). Navigation to 'about:blank' or same URL with different hash returns null.

Page.reload - reload page

Page.reload() is an async method (since v1.8, returns null|Response) that reloads the current page as if user triggered browser refresh. Returns main resource response; in case of redirects, resolves with last redirect response. Options: waitUntil (LoadState, since v1.8), timeout (number, since v1.8), signal (AbortSignal).

Page.setContent method

Page.setContent() (async, added in v1.8) internally calls document.write() with the provided HTML markup. Parameter: html (string). Options: timeout, signal, waitUntil.

Page.setDefaultNavigationTimeout method

Page.setDefaultNavigationTimeout() (added in v1.8) sets the default maximum navigation time in milliseconds for: Page.goBack, Page.goForward, Page.goto, Page.reload, Page.setContent, Page.waitForNavigation, and Page.waitForURL. Takes priority over Page.setDefaultTimeout, BrowserContext.setDefaultTimeout, and BrowserContext.setDefaultNavigationTimeout.

Page.setViewportSize method

Page.setViewportSize() (async, added in v1.8) resizes the page. For JavaScript/Python, accepts viewportSize object with width and height properties. For C#/Java, accepts width and height as separate parameters. Each page in a browser can have its own viewport. Note: resets screen size; use Browser.newContext with screen and viewport parameters for better control.

Page.url method

Page.url() (added in v1.8) returns the current page URL as a string.

Page.waitForURL method

Page.waitForURL() waits for the main frame to navigate to the given URL. It accepts a url parameter (supports glob patterns like '**/target.html'), an optional timeout option, an optional signal option, and an optional waitUntil option. Returns a promise that resolves when navigation completes.

Page.waitForURL usage example

Example showing Page.waitForURL: JavaScript: await page.click('a.delayed-navigation'); await page.waitForURL('**/target.html'); Python: page.click("a.delayed-navigation"); await page.wait_for_url("**/target.html");

Page.viewportSize method

Page.viewportSize() (added in v1.8) returns null or an object with width (page width in pixels) and height (page height in pixels) properties.

Page creates navigates and captures screenshots

Page provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. One Browser instance can have multiple Page instances. The basic workflow involves creating a browser, context, and page, then navigating to a URL and taking screenshots.

Page.addInitScript adds script evaluated on page load and navigation

The async method Page.addInitScript (since v1.8) adds a script which is evaluated in one of the following scenarios: whenever the page is navigated, or whenever a child frame is attached or navigated. The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment. The method returns a Disposable. Parameters: script (function, string, or Object with path and/or content), optional arg (only for function in JS). The method is useful for seeding Math.random before the page loads.

Page.addScriptTag adds script tag to page

The async method Page.addScriptTag (since v1.8) adds a <script> tag into the page with the desired URL or content. Returns an ElementHandle for the added tag when the script's onload fires or when the script content was injected into frame. Options: url (string), path (path to JS file), content (raw JavaScript), type (script type, use 'module' for ES6).

Page.addStyleTag adds stylesheet or style tag to page

The async method Page.addStyleTag (since v1.8) adds a <link rel="stylesheet"> tag into the page with the desired URL or a <style type="text/css"> tag with the content. Returns an ElementHandle for the added tag when the stylesheet's onload fires or when the CSS content was injected into frame. Options: url (string for <link> tag), path (path to CSS file), content (raw CSS content).

Page.bringToFront brings page to front

The async method Page.bringToFront (since v1.8) brings page to front, activating the tab.

Page.close closes page with optional unload handlers

The async method Page.close (since v1.8) closes the page. If runBeforeUnload is false (default), does not run any unload handlers and waits for the page to be closed. If runBeforeUnload is true, runs unload handlers but does not wait for the page to close. By default, page.close() does not run beforeunload handlers. Options: reason (string, since v1.40), runBeforeUnload (boolean, defaults to false).

Page.context returns browser context

The method Page.context (since v1.8) gets the browser context that the page belongs to. Return type: BrowserContext.

Page example creates browser context page and navigates

Example code showing basic Playwright workflow: creating a browser with webkit.launch(), creating a context with browser.newContext(), creating a page with context.newPage(), navigating to a URL with page.goto(), and taking a screenshot with page.screenshot(). This example is provided in multiple languages: JavaScript, Java, Python async, Python sync, and C#.

Page.addInitScript example overrides Math.random

Example showing Page.addInitScript usage. A preload.js file contains Math.random = () => 42; In the Playwright script, page.addInitScript({ path: './preload.js' }) loads this script before the page's own scripts run.

Page.addInitScript example with argument passing

Example showing Page.addInitScript with a callback function and argument. Code: await page.addInitScript(mock => { window.mock = mock; }, mock); This passes the mock object as an argument to the init script.

Give your agent this brain