Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->153.0.8010.12<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->26.6<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->155.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Chromium <!-- GEN:chromium-version -->156.0.8078.4<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->27.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->157.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |

## Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.jspecify.annotations.Nullable;
import com.microsoft.playwright.options.*;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.Pattern;

/**
* This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
Expand All @@ -43,6 +45,63 @@
* its own isolated cookie storage.
*/
public interface APIRequestContext {
class ClearCookiesOptions {
/**
* Only removes cookies with the given domain.
*/
public @Nullable Object domain;
/**
* Only removes cookies with the given name.
*/
public @Nullable Object name;
/**
* Only removes cookies with the given path.
*/
public @Nullable Object path;

/**
* Only removes cookies with the given domain.
*/
public ClearCookiesOptions setDomain(String domain) {
this.domain = domain;
return this;
}
/**
* Only removes cookies with the given domain.
*/
public ClearCookiesOptions setDomain(Pattern domain) {
this.domain = domain;
return this;
}
/**
* Only removes cookies with the given name.
*/
public ClearCookiesOptions setName(String name) {
this.name = name;
return this;
}
/**
* Only removes cookies with the given name.
*/
public ClearCookiesOptions setName(Pattern name) {
this.name = name;
return this;
}
/**
* Only removes cookies with the given path.
*/
public ClearCookiesOptions setPath(String path) {
this.path = path;
return this;
}
/**
* Only removes cookies with the given path.
*/
public ClearCookiesOptions setPath(Pattern path) {
this.path = path;
return this;
}
}
class DisposeOptions {
/**
* The reason to be reported to the operations interrupted by the context disposal.
Expand Down Expand Up @@ -95,6 +154,95 @@ public StorageStateOptions setPath(Path path) {
return this;
}
}
/**
* Adds cookies into this request context. They will be sent with matching subsequent requests. For {@link
* com.microsoft.playwright.BrowserContext#request BrowserContext.request()} and {@link
* com.microsoft.playwright.Page#request Page.request()}, this is equivalent to calling {@link
* com.microsoft.playwright.BrowserContext#addCookies BrowserContext.addCookies()} on the corresponding browser context.
*
* <p> <strong>Usage</strong>
* <pre>{@code
* request.addCookies(Arrays.asList(cookieObject1, cookieObject2));
* }</pre>
*
* @since v1.64
*/
void addCookies(List<Cookie> cookies);
/**
* Removes cookies from this request context. Accepts optional filter. For {@link
* com.microsoft.playwright.BrowserContext#request BrowserContext.request()} and {@link
* com.microsoft.playwright.Page#request Page.request()}, this is equivalent to calling {@link
* com.microsoft.playwright.BrowserContext#clearCookies BrowserContext.clearCookies()} on the corresponding browser
* context.
*
* <p> <strong>Usage</strong>
* <pre>{@code
* request.clearCookies();
* request.clearCookies(new APIRequestContext.ClearCookiesOptions().setName("session-id"));
* request.clearCookies(new APIRequestContext.ClearCookiesOptions().setDomain("my-origin.com"));
* request.clearCookies(new APIRequestContext.ClearCookiesOptions().setPath("/api/v1"));
* request.clearCookies(new APIRequestContext.ClearCookiesOptions()
* .setName("session-id")
* .setDomain("my-origin.com"));
* }</pre>
*
* @since v1.64
*/
default void clearCookies() {
clearCookies(null);
}
/**
* Removes cookies from this request context. Accepts optional filter. For {@link
* com.microsoft.playwright.BrowserContext#request BrowserContext.request()} and {@link
* com.microsoft.playwright.Page#request Page.request()}, this is equivalent to calling {@link
* com.microsoft.playwright.BrowserContext#clearCookies BrowserContext.clearCookies()} on the corresponding browser
* context.
*
* <p> <strong>Usage</strong>
* <pre>{@code
* request.clearCookies();
* request.clearCookies(new APIRequestContext.ClearCookiesOptions().setName("session-id"));
* request.clearCookies(new APIRequestContext.ClearCookiesOptions().setDomain("my-origin.com"));
* request.clearCookies(new APIRequestContext.ClearCookiesOptions().setPath("/api/v1"));
* request.clearCookies(new APIRequestContext.ClearCookiesOptions()
* .setName("session-id")
* .setDomain("my-origin.com"));
* }</pre>
*
* @since v1.64
*/
void clearCookies(@Nullable ClearCookiesOptions options);
/**
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
* are returned. For {@link com.microsoft.playwright.BrowserContext#request BrowserContext.request()} and {@link
* com.microsoft.playwright.Page#request Page.request()}, this is equivalent to calling {@link
* com.microsoft.playwright.BrowserContext#cookies BrowserContext.cookies()} on the corresponding browser context.
*
* @since v1.64
*/
default List<Cookie> cookies() {
return cookies((String) null);
}
/**
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
* are returned. For {@link com.microsoft.playwright.BrowserContext#request BrowserContext.request()} and {@link
* com.microsoft.playwright.Page#request Page.request()}, this is equivalent to calling {@link
* com.microsoft.playwright.BrowserContext#cookies BrowserContext.cookies()} on the corresponding browser context.
*
* @param urls Optional list of URLs.
* @since v1.64
*/
List<Cookie> cookies(@Nullable String urls);
/**
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
* are returned. For {@link com.microsoft.playwright.BrowserContext#request BrowserContext.request()} and {@link
* com.microsoft.playwright.Page#request Page.request()}, this is equivalent to calling {@link
* com.microsoft.playwright.BrowserContext#cookies BrowserContext.cookies()} on the corresponding browser context.
*
* @param urls Optional list of URLs.
* @since v1.64
*/
List<Cookie> cookies(@Nullable List<String> urls);
/**
* Sends HTTP(S) <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE">DELETE</a> request and returns
* its response. The method will populate request cookies from the context and update context cookies from the response.
Expand Down
42 changes: 34 additions & 8 deletions playwright/src/main/java/com/microsoft/playwright/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ class NewContextOptions {
public @Nullable Boolean ignoreHTTPSErrors;
/**
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
* so you don't actually need to set it manually. Defaults to {@code false}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
*/
public @Nullable Boolean isMobile;
/**
Expand Down Expand Up @@ -232,6 +232,11 @@ class NewContextOptions {
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
*/
public @Nullable Path recordVideoDir;
/**
* Frame rate of the recorded videos in frames per second. Defaults to {@code 25}. Firefox and WebKit currently capture up
* to 25 frames per second.
*/
public @Nullable Integer recordVideoFps;
/**
* Dimensions of the recorded videos. If not specified the size will be equal to {@code viewport} scaled down to fit into
* 800x800. If {@code viewport} is not configured explicitly the video size defaults to 800x450. Actual picture of each
Expand Down Expand Up @@ -451,8 +456,8 @@ public NewContextOptions setIgnoreHTTPSErrors(boolean ignoreHTTPSErrors) {
}
/**
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
* so you don't actually need to set it manually. Defaults to {@code false}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
*/
public NewContextOptions setIsMobile(boolean isMobile) {
this.isMobile = isMobile;
Expand Down Expand Up @@ -556,6 +561,14 @@ public NewContextOptions setRecordVideoDir(Path recordVideoDir) {
this.recordVideoDir = recordVideoDir;
return this;
}
/**
* Frame rate of the recorded videos in frames per second. Defaults to {@code 25}. Firefox and WebKit currently capture up
* to 25 frames per second.
*/
public NewContextOptions setRecordVideoFps(int recordVideoFps) {
this.recordVideoFps = recordVideoFps;
return this;
}
/**
* Dimensions of the recorded videos. If not specified the size will be equal to {@code viewport} scaled down to fit into
* 800x800. If {@code viewport} is not configured explicitly the video size defaults to 800x450. Actual picture of each
Expand Down Expand Up @@ -769,8 +782,8 @@ class NewPageOptions {
public @Nullable Boolean ignoreHTTPSErrors;
/**
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
* so you don't actually need to set it manually. Defaults to {@code false}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
*/
public @Nullable Boolean isMobile;
/**
Expand Down Expand Up @@ -828,6 +841,11 @@ class NewPageOptions {
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
*/
public @Nullable Path recordVideoDir;
/**
* Frame rate of the recorded videos in frames per second. Defaults to {@code 25}. Firefox and WebKit currently capture up
* to 25 frames per second.
*/
public @Nullable Integer recordVideoFps;
/**
* Dimensions of the recorded videos. If not specified the size will be equal to {@code viewport} scaled down to fit into
* 800x800. If {@code viewport} is not configured explicitly the video size defaults to 800x450. Actual picture of each
Expand Down Expand Up @@ -1047,8 +1065,8 @@ public NewPageOptions setIgnoreHTTPSErrors(boolean ignoreHTTPSErrors) {
}
/**
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
* so you don't actually need to set it manually. Defaults to {@code false}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
*/
public NewPageOptions setIsMobile(boolean isMobile) {
this.isMobile = isMobile;
Expand Down Expand Up @@ -1152,6 +1170,14 @@ public NewPageOptions setRecordVideoDir(Path recordVideoDir) {
this.recordVideoDir = recordVideoDir;
return this;
}
/**
* Frame rate of the recorded videos in frames per second. Defaults to {@code 25}. Firefox and WebKit currently capture up
* to 25 frames per second.
*/
public NewPageOptions setRecordVideoFps(int recordVideoFps) {
this.recordVideoFps = recordVideoFps;
return this;
}
/**
* Dimensions of the recorded videos. If not specified the size will be equal to {@code viewport} scaled down to fit into
* 800x800. If {@code viewport} is not configured explicitly the video size defaults to 800x450. Actual picture of each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class StorageStateOptions {
/**
* Set to {@code true} to include the context's virtual WebAuthn {@link com.microsoft.playwright.BrowserContext#credentials
* BrowserContext.credentials()} (passkeys) in the storage state snapshot. The captured credentials carry their private
* keys, so they can be re-seeded into a later context via the {@code storageState} option or {@link
* keys and signature counters, so they can be re-seeded into a later context via the {@code storageState} option or {@link
* com.microsoft.playwright.BrowserContext#setStorageState BrowserContext.setStorageState()}. Note that restoring the
* storage state that contains credentials will automatically install the virtual WebAuthn authenticator (see {@link
* com.microsoft.playwright.Credentials#install Credentials.install()}), and prevent all real authenticators from working
Expand Down Expand Up @@ -494,7 +494,7 @@ class StorageStateOptions {
/**
* Set to {@code true} to include the context's virtual WebAuthn {@link com.microsoft.playwright.BrowserContext#credentials
* BrowserContext.credentials()} (passkeys) in the storage state snapshot. The captured credentials carry their private
* keys, so they can be re-seeded into a later context via the {@code storageState} option or {@link
* keys and signature counters, so they can be re-seeded into a later context via the {@code storageState} option or {@link
* com.microsoft.playwright.BrowserContext#setStorageState BrowserContext.setStorageState()}. Note that restoring the
* storage state that contains credentials will automatically install the virtual WebAuthn authenticator (see {@link
* com.microsoft.playwright.Credentials#install Credentials.install()}), and prevent all real authenticators from working
Expand Down Expand Up @@ -1519,6 +1519,11 @@ default void routeFromHAR(Path har) {
*
*
* @param offline Whether to emulate network being offline for the browser context.
*
* <p> <strong>NOTE:</strong> Offline emulation only affects requests that go through the browser's regular network stack, such as page navigations,
* {@code fetch()}, {@code XMLHttpRequest} and WebSockets. It does not affect WebRTC traffic: established {@code
* RTCPeerConnection}s keep sending and receiving media over UDP. To test WebRTC connection loss, interrupt the connection
* outside the browser, for example by stopping the TURN server or using an OS-level firewall.
* @since v1.8
*/
void setOffline(boolean offline);
Expand Down
Loading
Loading