feat: roll driver, switch to new api.json format (#199)
This commit is contained in:
@@ -26,12 +26,12 @@ jobs:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: ${{ runner.os }}-m2
|
||||
- name: Cache Downloaded Drivers
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: driver-bundle/src/main/resources/driver
|
||||
key: ${{ runner.os }}-drivers-${{ hashFiles('scripts/*') }}
|
||||
restore-keys: ${{ runner.os }}-drivers
|
||||
# - name: Cache Downloaded Drivers
|
||||
# uses: actions/cache@v2
|
||||
# with:
|
||||
# path: driver-bundle/src/main/resources/driver
|
||||
# key: ${{ runner.os }}-drivers-${{ hashFiles('scripts/*') }}
|
||||
# restore-keys: ${{ runner.os }}-drivers
|
||||
- name: Download drivers
|
||||
shell: bash
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DriverJar extends Driver {
|
||||
String cliFileName = super.cliFileName();
|
||||
Path driver = driverTempDir.resolve(cliFileName);
|
||||
if (!Files.exists(driver)) {
|
||||
throw new RuntimeException("Failed to find playwright-cli");
|
||||
throw new RuntimeException("Failed to find " + cliFileName + " at " + driver);
|
||||
}
|
||||
ProcessBuilder pb = new ProcessBuilder(driver.toString(), "install");
|
||||
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
@@ -50,14 +50,30 @@ public class DriverJar extends Driver {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isExecutable(Path filePath) {
|
||||
String name = filePath.getFileName().toString();
|
||||
return name.endsWith(".sh") || name.endsWith(".exe") || !name.contains(".");
|
||||
}
|
||||
|
||||
private void extractDriverToTempDir() throws URISyntaxException, IOException {
|
||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||
URI uri = classloader.getResource("driver/" + platformDir()).toURI();
|
||||
// Create zip filesystem if loading from jar.
|
||||
try (FileSystem fileSystem = "jar".equals(uri.getScheme()) ? FileSystems.newFileSystem(uri, Collections.emptyMap()) : null) {
|
||||
Files.list(Paths.get(uri)).forEach(filePath -> {
|
||||
Path srcRoot = Paths.get(uri);
|
||||
Files.walk(srcRoot).forEach(fromPath -> {
|
||||
Path relative = srcRoot.relativize(fromPath);
|
||||
Path toPath = driverTempDir.resolve(relative.toString());
|
||||
try {
|
||||
extractResource(filePath, driverTempDir);
|
||||
if (Files.isDirectory(fromPath)) {
|
||||
Files.createDirectories(toPath);
|
||||
} else {
|
||||
Files.copy(fromPath, toPath);
|
||||
if (isExecutable(toPath)) {
|
||||
toPath.toFile().setExecutable(true, true);
|
||||
}
|
||||
}
|
||||
toPath.toFile().deleteOnExit();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to extract driver from " + uri, e);
|
||||
}
|
||||
@@ -79,14 +95,6 @@ public class DriverJar extends Driver {
|
||||
throw new RuntimeException("Unexpected os.name value: " + name);
|
||||
}
|
||||
|
||||
private static Path extractResource(Path from, Path toDir) throws IOException {
|
||||
Path path = toDir.resolve(from.getFileName().toString());
|
||||
Files.copy(from, path);
|
||||
path.toFile().setExecutable(true);
|
||||
path.toFile().deleteOnExit();
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
Path driverDir() {
|
||||
return driverTempDir;
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestInstall {
|
||||
@@ -30,14 +31,19 @@ public class TestInstall {
|
||||
void playwrightCliInstalled() throws Exception {
|
||||
// Clear system property to ensure that the driver is loaded from jar.
|
||||
System.clearProperty("playwright.cli.dir");
|
||||
Path cli = Driver.ensureDriverInstalled();
|
||||
assertTrue(Files.exists(cli));
|
||||
try {
|
||||
Path cli = Driver.ensureDriverInstalled();
|
||||
assertTrue(Files.exists(cli));
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cli.toString(), "install");
|
||||
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
|
||||
Process p = pb.start();
|
||||
boolean result = p.waitFor(1, TimeUnit.MINUTES);
|
||||
assertTrue(result, "Timed out waiting for browsers to install");
|
||||
ProcessBuilder pb = new ProcessBuilder(cli.toString(), "install");
|
||||
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
|
||||
Process p = pb.start();
|
||||
boolean result = p.waitFor(1, TimeUnit.MINUTES);
|
||||
assertTrue(result, "Timed out waiting for browsers to install");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class Driver {
|
||||
|
||||
protected String cliFileName() {
|
||||
return System.getProperty("os.name").toLowerCase().contains("windows") ?
|
||||
"playwright-cli.exe" : "playwright-cli";
|
||||
"playwright.cmd" : "playwright.sh";
|
||||
}
|
||||
|
||||
private static Driver createDriver() throws Exception {
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>playwright</artifactId>
|
||||
<version>0.171.0</version>
|
||||
<version>0.180.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
||||
@@ -19,13 +19,25 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as screen readers or switches.
|
||||
* The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
|
||||
* <p>
|
||||
* Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output.
|
||||
* assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
|
||||
* <p>
|
||||
* Blink - Chromium's rendering engine - has a concept of "accessibility tree", which is then translated into different platform-specific APIs. Accessibility namespace gives users access to the Blink Accessibility Tree.
|
||||
* [switches](https://en.wikipedia.org/wiki/Switch_access).
|
||||
* <p>
|
||||
* Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing only the "interesting" nodes of the tree.
|
||||
* Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might
|
||||
* <p>
|
||||
* have wildly different output.
|
||||
* <p>
|
||||
* Blink - Chromium's rendering engine - has a concept of "accessibility tree", which is then translated into different
|
||||
* <p>
|
||||
* platform-specific APIs. Accessibility namespace gives users access to the Blink Accessibility Tree.
|
||||
* <p>
|
||||
* Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or by
|
||||
* <p>
|
||||
* assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing only the
|
||||
* <p>
|
||||
* "interesting" nodes of the tree.
|
||||
*/
|
||||
public interface Accessibility {
|
||||
class SnapshotOptions {
|
||||
@@ -51,9 +63,17 @@ public interface Accessibility {
|
||||
return snapshot(null);
|
||||
}
|
||||
/**
|
||||
* Captures the current state of the accessibility tree. The returned object represents the root accessible node of the page.
|
||||
* Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
|
||||
* <p>
|
||||
* <strong>NOTE</strong> The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers. Playwright will discard them as well for an easier to process tree, unless {@code interestingOnly} is set to {@code false}.
|
||||
* page.
|
||||
* <p>
|
||||
* > <strong>NOTE</strong> The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers.
|
||||
* <p>
|
||||
* Playwright will discard them as well for an easier to process tree, unless {@code interestingOnly} is set to {@code false}.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
AccessibilityNode snapshot(SnapshotOptions options);
|
||||
|
||||
@@ -20,8 +20,19 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A Browser is created when Playwright connects to a browser instance, either through {@code browserType.launch([options])} or {@code browserType.connect(params)}.
|
||||
* - extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||||
* <p>
|
||||
* A Browser is created when Playwright connects to a browser instance, either through [{@code method: BrowserType.launch}] or
|
||||
* <p>
|
||||
* [{@code method: BrowserType.connect}].
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* See {@code ChromiumBrowser}, [FirefoxBrowser] and [WebKitBrowser] for browser-specific features. Note that
|
||||
* <p>
|
||||
* [{@code method: BrowserType.connect}] and [{@code method: BrowserType.launch}] always return a specific browser instance, based on
|
||||
* <p>
|
||||
* the browser being connected to or launched.
|
||||
*/
|
||||
public interface Browser {
|
||||
class VideoSize {
|
||||
@@ -49,59 +60,10 @@ public interface Browser {
|
||||
void addListener(EventType type, Listener<EventType> listener);
|
||||
void removeListener(EventType type, Listener<EventType> listener);
|
||||
class NewContextOptions {
|
||||
public class RecordHar {
|
||||
/**
|
||||
* Optional setting to control whether to omit request content from the HAR. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean omitContent;
|
||||
/**
|
||||
* Path on the filesystem to write the HAR file to.
|
||||
*/
|
||||
public Path path;
|
||||
|
||||
RecordHar() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public RecordHar withOmitContent(Boolean omitContent) {
|
||||
this.omitContent = omitContent;
|
||||
return this;
|
||||
}
|
||||
public RecordHar withPath(Path path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class RecordVideo {
|
||||
/**
|
||||
* Path to the directory to put videos into.
|
||||
*/
|
||||
public Path dir;
|
||||
/**
|
||||
* Optional dimensions of the recorded videos. If not specified the size will be equal to {@code viewport}. If {@code viewport} is not configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary to fit the specified size.
|
||||
*/
|
||||
public VideoSize size;
|
||||
|
||||
RecordVideo() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public RecordVideo withDir(Path dir) {
|
||||
this.dir = dir;
|
||||
return this;
|
||||
}
|
||||
public RecordVideo withSize(int width, int height) {
|
||||
this.size = new VideoSize(width, height);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Proxy {
|
||||
/**
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or
|
||||
* {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
*/
|
||||
public String server;
|
||||
/**
|
||||
@@ -140,157 +102,213 @@ public interface Browser {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class RecordHar {
|
||||
/**
|
||||
* Optional setting to control whether to omit request content from the HAR. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean omitContent;
|
||||
/**
|
||||
* Path on the filesystem to write the HAR file to.
|
||||
*/
|
||||
public Path path;
|
||||
|
||||
RecordHar() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public RecordHar withOmitContent(Boolean omitContent) {
|
||||
this.omitContent = omitContent;
|
||||
return this;
|
||||
}
|
||||
public RecordHar withPath(Path path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class RecordVideo {
|
||||
/**
|
||||
* Path to the directory to put videos into.
|
||||
*/
|
||||
public Path dir;
|
||||
/**
|
||||
* Optional dimensions of the recorded videos. If not specified the size will be equal to {@code viewport}. If {@code viewport} is not
|
||||
* configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary
|
||||
* to fit the specified size.
|
||||
*/
|
||||
public VideoSize size;
|
||||
|
||||
RecordVideo() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public RecordVideo withDir(Path dir) {
|
||||
this.dir = dir;
|
||||
return this;
|
||||
}
|
||||
public RecordVideo withSize(int width, int height) {
|
||||
this.size = new VideoSize(width, height);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Whether to automatically download all the attachments. Defaults to {@code false} where all the downloads are canceled.
|
||||
*/
|
||||
public Boolean acceptDownloads;
|
||||
/**
|
||||
* Whether to ignore HTTPS errors during navigation. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default viewport.
|
||||
* Emulates {@code 'prefers-colors-scheme'} media feature, supported values are {@code 'light'}, {@code 'dark'}, {@code 'no-preference'}. See
|
||||
* [{@code method: Page.emulateMedia}] for more details. Defaults to '{@code light}'.
|
||||
*/
|
||||
public Page.Viewport viewport;
|
||||
/**
|
||||
* Specific user agent to use in this context.
|
||||
*/
|
||||
public String userAgent;
|
||||
public ColorScheme colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public Integer deviceScaleFactor;
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported in Firefox.
|
||||
* An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
|
||||
*/
|
||||
public BrowserContext.HTTPCredentials httpCredentials;
|
||||
/**
|
||||
* Whether to ignore HTTPS errors during navigation. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Changes the timezone of the context. See ICU’s {@code metaZones.txt} for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@code browserContext.grantPermissions(permissions[, options])} for more details.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* Credentials for HTTP authentication.
|
||||
* A list of permissions to grant to all pages in this context. See [{@code method: BrowserContext.grantPermissions}] for more
|
||||
* details.
|
||||
*/
|
||||
public BrowserContext.HTTPCredentials httpCredentials;
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Emulates {@code 'prefers-colors-scheme'} media feature, supported values are {@code 'light'}, {@code 'dark'}, {@code 'no-preference'}. See {@code page.emulateMedia(params)} for more details. Defaults to '{@code light}'.
|
||||
*/
|
||||
public ColorScheme colorScheme;
|
||||
/**
|
||||
* Enables HAR recording for all pages into {@code recordHar.path} file. If not specified, the HAR is not recorded. Make sure to await {@code browserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public RecordHar recordHar;
|
||||
/**
|
||||
* Enables video recording for all pages into {@code recordVideo.dir} directory. If not specified videos are not recorded. Make sure to await {@code browserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public RecordVideo recordVideo;
|
||||
/**
|
||||
* Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server: 'per-context' } })}.
|
||||
* Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this
|
||||
* option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
|
||||
* {@code launch({ proxy: { server: 'per-context' } })}.
|
||||
*/
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via {@code browserContext.storageState([options])}. Either a path to the file with saved storage, or an object with the following fields:
|
||||
* Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into {@code recordHar.path} file. If not
|
||||
* specified, the HAR is not recorded. Make sure to await [{@code method: BrowserContext.close}] for the HAR to be saved.
|
||||
*/
|
||||
public RecordHar recordHar;
|
||||
/**
|
||||
* Enables video recording for all pages into {@code recordVideo.dir} directory. If not specified videos are not recorded. Make
|
||||
* sure to await [{@code method: BrowserContext.close}] for videos to be saved.
|
||||
*/
|
||||
public RecordVideo recordVideo;
|
||||
/**
|
||||
* Populates context with given storage state. This method can be used to initialize context with logged-in information
|
||||
* obtained via [{@code method: BrowserContext.storageState}]. Either a path to the file with saved storage, or an object with
|
||||
* the following fields:
|
||||
*/
|
||||
public BrowserContext.StorageState storageState;
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
* Changes the timezone of the context. See
|
||||
* [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
|
||||
* for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
* Specific user agent to use in this context.
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default viewport.
|
||||
*/
|
||||
public Page.Viewport viewport;
|
||||
|
||||
public NewContextOptions withAcceptDownloads(Boolean acceptDownloads) {
|
||||
this.acceptDownloads = acceptDownloads;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
|
||||
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withBypassCSP(Boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
public NewContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withDeviceScaleFactor(Integer deviceScaleFactor) {
|
||||
public NewContextOptions withDeviceScaleFactor(Double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withIsMobile(Boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withHasTouch(Boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withGeolocation(Geolocation geolocation) {
|
||||
this.geolocation = geolocation;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withOffline(Boolean offline) {
|
||||
this.offline = offline;
|
||||
public NewContextOptions withGeolocation(Geolocation geolocation) {
|
||||
this.geolocation = geolocation;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withHasTouch(Boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new BrowserContext.HTTPCredentials(username, password);
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
public NewContextOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
|
||||
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withIsMobile(Boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withOffline(Boolean offline) {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
public Proxy setProxy() {
|
||||
this.proxy = new Proxy();
|
||||
return this.proxy;
|
||||
}
|
||||
public RecordHar setRecordHar() {
|
||||
this.recordHar = new RecordHar();
|
||||
return this.recordHar;
|
||||
@@ -299,10 +317,6 @@ public interface Browser {
|
||||
this.recordVideo = new RecordVideo();
|
||||
return this.recordVideo;
|
||||
}
|
||||
public Proxy setProxy() {
|
||||
this.proxy = new Proxy();
|
||||
return this.proxy;
|
||||
}
|
||||
public NewContextOptions withStorageState(BrowserContext.StorageState storageState) {
|
||||
this.storageState = storageState;
|
||||
this.storageStatePath = null;
|
||||
@@ -313,6 +327,18 @@ public interface Browser {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withDevice(DeviceDescriptor device) {
|
||||
withViewport(device.viewport().width(), device.viewport().height());
|
||||
withUserAgent(device.userAgent());
|
||||
@@ -323,59 +349,10 @@ public interface Browser {
|
||||
}
|
||||
}
|
||||
class NewPageOptions {
|
||||
public class RecordHar {
|
||||
/**
|
||||
* Optional setting to control whether to omit request content from the HAR. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean omitContent;
|
||||
/**
|
||||
* Path on the filesystem to write the HAR file to.
|
||||
*/
|
||||
public Path path;
|
||||
|
||||
RecordHar() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public RecordHar withOmitContent(Boolean omitContent) {
|
||||
this.omitContent = omitContent;
|
||||
return this;
|
||||
}
|
||||
public RecordHar withPath(Path path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class RecordVideo {
|
||||
/**
|
||||
* Path to the directory to put videos into.
|
||||
*/
|
||||
public Path dir;
|
||||
/**
|
||||
* Optional dimensions of the recorded videos. If not specified the size will be equal to {@code viewport}. If {@code viewport} is not configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary to fit the specified size.
|
||||
*/
|
||||
public VideoSize size;
|
||||
|
||||
RecordVideo() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public RecordVideo withDir(Path dir) {
|
||||
this.dir = dir;
|
||||
return this;
|
||||
}
|
||||
public RecordVideo withSize(int width, int height) {
|
||||
this.size = new VideoSize(width, height);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Proxy {
|
||||
/**
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or
|
||||
* {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
*/
|
||||
public String server;
|
||||
/**
|
||||
@@ -414,157 +391,213 @@ public interface Browser {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class RecordHar {
|
||||
/**
|
||||
* Optional setting to control whether to omit request content from the HAR. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean omitContent;
|
||||
/**
|
||||
* Path on the filesystem to write the HAR file to.
|
||||
*/
|
||||
public Path path;
|
||||
|
||||
RecordHar() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public RecordHar withOmitContent(Boolean omitContent) {
|
||||
this.omitContent = omitContent;
|
||||
return this;
|
||||
}
|
||||
public RecordHar withPath(Path path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class RecordVideo {
|
||||
/**
|
||||
* Path to the directory to put videos into.
|
||||
*/
|
||||
public Path dir;
|
||||
/**
|
||||
* Optional dimensions of the recorded videos. If not specified the size will be equal to {@code viewport}. If {@code viewport} is not
|
||||
* configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary
|
||||
* to fit the specified size.
|
||||
*/
|
||||
public VideoSize size;
|
||||
|
||||
RecordVideo() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public RecordVideo withDir(Path dir) {
|
||||
this.dir = dir;
|
||||
return this;
|
||||
}
|
||||
public RecordVideo withSize(int width, int height) {
|
||||
this.size = new VideoSize(width, height);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Whether to automatically download all the attachments. Defaults to {@code false} where all the downloads are canceled.
|
||||
*/
|
||||
public Boolean acceptDownloads;
|
||||
/**
|
||||
* Whether to ignore HTTPS errors during navigation. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default viewport.
|
||||
* Emulates {@code 'prefers-colors-scheme'} media feature, supported values are {@code 'light'}, {@code 'dark'}, {@code 'no-preference'}. See
|
||||
* [{@code method: Page.emulateMedia}] for more details. Defaults to '{@code light}'.
|
||||
*/
|
||||
public Page.Viewport viewport;
|
||||
/**
|
||||
* Specific user agent to use in this context.
|
||||
*/
|
||||
public String userAgent;
|
||||
public ColorScheme colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public Integer deviceScaleFactor;
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported in Firefox.
|
||||
* An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
|
||||
*/
|
||||
public BrowserContext.HTTPCredentials httpCredentials;
|
||||
/**
|
||||
* Whether to ignore HTTPS errors during navigation. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Changes the timezone of the context. See ICU’s {@code metaZones.txt} for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@code browserContext.grantPermissions(permissions[, options])} for more details.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* Credentials for HTTP authentication.
|
||||
* A list of permissions to grant to all pages in this context. See [{@code method: BrowserContext.grantPermissions}] for more
|
||||
* details.
|
||||
*/
|
||||
public BrowserContext.HTTPCredentials httpCredentials;
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Emulates {@code 'prefers-colors-scheme'} media feature, supported values are {@code 'light'}, {@code 'dark'}, {@code 'no-preference'}. See {@code page.emulateMedia(params)} for more details. Defaults to '{@code light}'.
|
||||
*/
|
||||
public ColorScheme colorScheme;
|
||||
/**
|
||||
* Enables HAR recording for all pages into {@code recordHar.path} file. If not specified, the HAR is not recorded. Make sure to await {@code browserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public RecordHar recordHar;
|
||||
/**
|
||||
* Enables video recording for all pages into {@code recordVideo.dir} directory. If not specified videos are not recorded. Make sure to await {@code browserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public RecordVideo recordVideo;
|
||||
/**
|
||||
* Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server: 'per-context' } })}.
|
||||
* Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this
|
||||
* option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
|
||||
* {@code launch({ proxy: { server: 'per-context' } })}.
|
||||
*/
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via {@code browserContext.storageState([options])}. Either a path to the file with saved storage, or an object with the following fields:
|
||||
* Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into {@code recordHar.path} file. If not
|
||||
* specified, the HAR is not recorded. Make sure to await [{@code method: BrowserContext.close}] for the HAR to be saved.
|
||||
*/
|
||||
public RecordHar recordHar;
|
||||
/**
|
||||
* Enables video recording for all pages into {@code recordVideo.dir} directory. If not specified videos are not recorded. Make
|
||||
* sure to await [{@code method: BrowserContext.close}] for videos to be saved.
|
||||
*/
|
||||
public RecordVideo recordVideo;
|
||||
/**
|
||||
* Populates context with given storage state. This method can be used to initialize context with logged-in information
|
||||
* obtained via [{@code method: BrowserContext.storageState}]. Either a path to the file with saved storage, or an object with
|
||||
* the following fields:
|
||||
*/
|
||||
public BrowserContext.StorageState storageState;
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
* Changes the timezone of the context. See
|
||||
* [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
|
||||
* for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
* Specific user agent to use in this context.
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default viewport.
|
||||
*/
|
||||
public Page.Viewport viewport;
|
||||
|
||||
public NewPageOptions withAcceptDownloads(Boolean acceptDownloads) {
|
||||
this.acceptDownloads = acceptDownloads;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
|
||||
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withBypassCSP(Boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
public NewPageOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withDeviceScaleFactor(Integer deviceScaleFactor) {
|
||||
public NewPageOptions withDeviceScaleFactor(Double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withIsMobile(Boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withHasTouch(Boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withGeolocation(Geolocation geolocation) {
|
||||
this.geolocation = geolocation;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withOffline(Boolean offline) {
|
||||
this.offline = offline;
|
||||
public NewPageOptions withGeolocation(Geolocation geolocation) {
|
||||
this.geolocation = geolocation;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withHasTouch(Boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new BrowserContext.HTTPCredentials(username, password);
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
public NewPageOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
|
||||
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withIsMobile(Boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withOffline(Boolean offline) {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
public Proxy setProxy() {
|
||||
this.proxy = new Proxy();
|
||||
return this.proxy;
|
||||
}
|
||||
public RecordHar setRecordHar() {
|
||||
this.recordHar = new RecordHar();
|
||||
return this.recordHar;
|
||||
@@ -573,10 +606,6 @@ public interface Browser {
|
||||
this.recordVideo = new RecordVideo();
|
||||
return this.recordVideo;
|
||||
}
|
||||
public Proxy setProxy() {
|
||||
this.proxy = new Proxy();
|
||||
return this.proxy;
|
||||
}
|
||||
public NewPageOptions withStorageState(BrowserContext.StorageState storageState) {
|
||||
this.storageState = storageState;
|
||||
this.storageStatePath = null;
|
||||
@@ -587,6 +616,18 @@ public interface Browser {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withDevice(DeviceDescriptor device) {
|
||||
withViewport(device.viewport().width(), device.viewport().height());
|
||||
withUserAgent(device.userAgent());
|
||||
@@ -597,16 +638,22 @@ public interface Browser {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* In case this browser is obtained using {@code browserType.launch([options])}, closes the browser and all of its pages (if any were opened).
|
||||
* In case this browser is obtained using [{@code method: BrowserType.launch}], closes the browser and all of its pages (if any
|
||||
* <p>
|
||||
* In case this browser is obtained using {@code browserType.connect(params)}, clears all created contexts belonging to this browser and disconnects from the browser server.
|
||||
* were opened).
|
||||
* <p>
|
||||
* The Browser object itself is considered to be disposed and cannot be used anymore.
|
||||
* In case this browser is obtained using [{@code method: BrowserType.connect}], clears all created contexts belonging to this
|
||||
* <p>
|
||||
* browser and disconnects from the browser server.
|
||||
* <p>
|
||||
* The {@code Browser} object itself is considered to be disposed and cannot be used anymore.
|
||||
*/
|
||||
void close();
|
||||
/**
|
||||
* Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
List<BrowserContext> contexts();
|
||||
/**
|
||||
@@ -619,6 +666,8 @@ public interface Browser {
|
||||
/**
|
||||
* Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
BrowserContext newContext(NewContextOptions options);
|
||||
default Page newPage() {
|
||||
@@ -627,7 +676,11 @@ public interface Browser {
|
||||
/**
|
||||
* Creates a new page in a new browser context. Closing this page will close the context as well.
|
||||
* <p>
|
||||
* This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and testing frameworks should explicitly create {@code browser.newContext([options])} followed by the {@code browserContext.newPage()} to control their exact life times.
|
||||
* This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
|
||||
* <p>
|
||||
* testing frameworks should explicitly create [{@code method: Browser.newContext}] followed by the
|
||||
* <p>
|
||||
* [{@code method: BrowserContext.newPage}] to control their exact life times.
|
||||
*/
|
||||
Page newPage(NewPageOptions options);
|
||||
/**
|
||||
|
||||
@@ -23,11 +23,19 @@ import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* - extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||||
* <p>
|
||||
* BrowserContexts provide a way to operate multiple independent browser sessions.
|
||||
* <p>
|
||||
* If a page opens another page, e.g. with a {@code window.open} call, the popup will belong to the parent page's browser context.
|
||||
* If a page opens another page, e.g. with a {@code window.open} call, the popup will belong to the parent page's browser
|
||||
* <p>
|
||||
* Playwright allows creation of "incognito" browser contexts with {@code browser.newContext()} method. "Incognito" browser contexts don't write any browsing data to disk.
|
||||
* context.
|
||||
* <p>
|
||||
* Playwright allows creation of "incognito" browser contexts with {@code browser.newContext()} method. "Incognito" browser
|
||||
* <p>
|
||||
* contexts don't write any browsing data to disk.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface BrowserContext {
|
||||
@@ -121,23 +129,32 @@ public interface BrowserContext {
|
||||
*/
|
||||
public String value;
|
||||
/**
|
||||
* either url or domain / path are required
|
||||
* either url or domain / path are required. Optional.
|
||||
*/
|
||||
public String url;
|
||||
/**
|
||||
* either url or domain / path are required
|
||||
* either url or domain / path are required Optional.
|
||||
*/
|
||||
public String domain;
|
||||
/**
|
||||
* either url or domain / path are required
|
||||
* either url or domain / path are required Optional.
|
||||
*/
|
||||
public String path;
|
||||
/**
|
||||
* Unix time in seconds.
|
||||
* Unix time in seconds. Optional.
|
||||
*/
|
||||
public Long expires;
|
||||
/**
|
||||
* Optional.
|
||||
*/
|
||||
public Boolean httpOnly;
|
||||
/**
|
||||
* Optional.
|
||||
*/
|
||||
public Boolean secure;
|
||||
/**
|
||||
* Optional.
|
||||
*/
|
||||
public SameSite sameSite;
|
||||
|
||||
public AddCookie withName(String name) {
|
||||
@@ -217,7 +234,8 @@ public interface BrowserContext {
|
||||
}
|
||||
class ExposeBindingOptions {
|
||||
/**
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported.
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
* supported. When passing by value, multiple arguments are supported.
|
||||
*/
|
||||
public Boolean handle;
|
||||
|
||||
@@ -228,7 +246,7 @@ public interface BrowserContext {
|
||||
}
|
||||
class GrantPermissionsOptions {
|
||||
/**
|
||||
* The origin to grant permissions to, e.g. "https://example.com".
|
||||
* The [origin] to grant permissions to, e.g. "https://example.com".
|
||||
*/
|
||||
public String origin;
|
||||
|
||||
@@ -239,7 +257,9 @@ public interface BrowserContext {
|
||||
}
|
||||
class StorageStateOptions {
|
||||
/**
|
||||
* The file path to save the storage state to. If {@code path} is a relative path, then it is resolved relative to current working directory. If no path is provided, storage state is still returned, but won't be saved to the disk.
|
||||
* The file path to save the storage state to. If {@code path} is a relative path, then it is resolved relative to
|
||||
* [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, storage
|
||||
* state is still returned, but won't be saved to the disk.
|
||||
*/
|
||||
public Path path;
|
||||
|
||||
@@ -249,7 +269,11 @@ public interface BrowserContext {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be obtained via {@code browserContext.cookies([urls])}.
|
||||
* Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
||||
* <p>
|
||||
* obtained via [{@code method: BrowserContext.cookies}].
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
void addCookies(List<AddCookie> cookies);
|
||||
@@ -259,15 +283,23 @@ public interface BrowserContext {
|
||||
/**
|
||||
* Adds a script which would be evaluated in one of the following scenarios:
|
||||
* <p>
|
||||
* Whenever a page is created in the browser context or is navigated.
|
||||
* - Whenever a page is created in the browser context or is navigated.
|
||||
* <p>
|
||||
* Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is evaluated in the context of the newly attached frame.
|
||||
* - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
|
||||
* <p>
|
||||
* 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, e.g. to seed {@code Math.random}.
|
||||
* evaluated in the context of the newly attached frame.
|
||||
* <p>
|
||||
* The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
||||
* <p>
|
||||
* the JavaScript environment, e.g. to seed {@code Math.random}.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE</strong> The order of evaluation of multiple scripts installed via {@code browserContext.addInitScript(script[, arg])} and {@code page.addInitScript(script[, arg])} is not defined.
|
||||
*
|
||||
* <p>
|
||||
* > <strong>NOTE</strong> The order of evaluation of multiple scripts installed via [{@code method: BrowserContext.addInitScript}] and
|
||||
* <p>
|
||||
* [{@code method: Page.addInitScript}] is not defined.
|
||||
* @param script Script to be evaluated in all pages in the browser context.
|
||||
* @param arg Optional argument to pass to {@code script} (only supported when passing a function).
|
||||
*/
|
||||
@@ -283,66 +315,90 @@ public interface BrowserContext {
|
||||
/**
|
||||
* Clears all permission overrides for the browser context.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
void clearPermissions();
|
||||
/**
|
||||
* Closes the browser context. All the pages that belong to the browser context will be closed.
|
||||
* <p>
|
||||
* <strong>NOTE</strong> the default browser context cannot be closed.
|
||||
* > <strong>NOTE</strong> the default browser context cannot be closed.
|
||||
*/
|
||||
void close();
|
||||
default List<Cookie> cookies() { return cookies((List<String>) null); }
|
||||
default List<Cookie> cookies(String url) { return cookies(Arrays.asList(url)); }
|
||||
/**
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned.
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
||||
* <p>
|
||||
* are returned.
|
||||
* @param urls Optional list of URLs.
|
||||
*/
|
||||
List<Cookie> cookies(List<String> urls);
|
||||
default void exposeBinding(String name, Page.Binding playwrightBinding) {
|
||||
exposeBinding(name, playwrightBinding, null);
|
||||
default void exposeBinding(String name, Page.Binding callback) {
|
||||
exposeBinding(name, callback, null);
|
||||
}
|
||||
/**
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in every page in the context. When called, the function executes {@code playwrightBinding} and returns a Promise which resolves to the return value of {@code playwrightBinding}. If the {@code playwrightBinding} returns a Promise, it will be awaited.
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in every page in the context. When
|
||||
* <p>
|
||||
* The first argument of the {@code playwrightBinding} function contains information about the caller: {@code { browserContext: BrowserContext, page: Page, frame: Frame }}.
|
||||
* called, the function executes {@code callback} and returns a [Promise] which resolves to the return value of {@code callback}. If
|
||||
* <p>
|
||||
* See {@code page.exposeBinding(name, playwrightBinding[, options])} for page-only version.
|
||||
* the {@code callback} returns a [Promise], it will be awaited.
|
||||
* <p>
|
||||
* The first argument of the {@code callback} function contains information about the caller: `{ browserContext: BrowserContext,
|
||||
* <p>
|
||||
* page: Page, frame: Frame }`.
|
||||
* <p>
|
||||
* See [{@code method: Page.exposeBinding}] for page-only version.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param playwrightBinding Callback function that will be called in the Playwright's context.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
*/
|
||||
void exposeBinding(String name, Page.Binding playwrightBinding, ExposeBindingOptions options);
|
||||
void exposeBinding(String name, Page.Binding callback, ExposeBindingOptions options);
|
||||
/**
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in every page in the context. When called, the function executes {@code playwrightFunction} and returns a Promise which resolves to the return value of {@code playwrightFunction}.
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in every page in the context. When
|
||||
* <p>
|
||||
* If the {@code playwrightFunction} returns a Promise, it will be awaited.
|
||||
* called, the function executes {@code callback} and returns a [Promise] which resolves to the return value of {@code callback}.
|
||||
* <p>
|
||||
* See {@code page.exposeFunction(name, playwrightFunction)} for page-only version.
|
||||
* If the {@code callback} returns a [Promise], it will be awaited.
|
||||
* <p>
|
||||
* See [{@code method: Page.exposeFunction}] for page-only version.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param playwrightFunction Callback function that will be called in the Playwright's context.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
*/
|
||||
void exposeFunction(String name, Page.Function playwrightFunction);
|
||||
void exposeFunction(String name, Page.Function callback);
|
||||
default void grantPermissions(List<String> permissions) {
|
||||
grantPermissions(permissions, null);
|
||||
}
|
||||
/**
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if specified.
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
||||
* <p>
|
||||
* specified.
|
||||
* @param permissions A permission or an array of permissions to grant. Permissions can be one of the following values:
|
||||
* - {@code 'geolocation'}
|
||||
* - {@code 'midi'}
|
||||
* - {@code 'midi-sysex'} (system-exclusive midi)
|
||||
* - {@code 'notifications'}
|
||||
* - {@code 'push'}
|
||||
* - {@code 'camera'}
|
||||
* - {@code 'microphone'}
|
||||
* - {@code 'background-sync'}
|
||||
* - {@code 'ambient-light-sensor'}
|
||||
* - {@code 'accelerometer'}
|
||||
* - {@code 'gyroscope'}
|
||||
* - {@code 'magnetometer'}
|
||||
* - {@code 'accessibility-events'}
|
||||
* - {@code 'clipboard-read'}
|
||||
* - {@code 'clipboard-write'}
|
||||
* - {@code 'payment-handler'}
|
||||
* - {@code 'geolocation'}
|
||||
* - {@code 'midi'}
|
||||
* - {@code 'midi-sysex'} (system-exclusive midi)
|
||||
* - {@code 'notifications'}
|
||||
* - {@code 'push'}
|
||||
* - {@code 'camera'}
|
||||
* - {@code 'microphone'}
|
||||
* - {@code 'background-sync'}
|
||||
* - {@code 'ambient-light-sensor'}
|
||||
* - {@code 'accelerometer'}
|
||||
* - {@code 'gyroscope'}
|
||||
* - {@code 'magnetometer'}
|
||||
* - {@code 'accessibility-events'}
|
||||
* - {@code 'clipboard-read'}
|
||||
* - {@code 'clipboard-write'}
|
||||
* - {@code 'payment-handler'}
|
||||
*/
|
||||
void grantPermissions(List<String> permissions, GrantPermissionsOptions options);
|
||||
/**
|
||||
@@ -350,55 +406,71 @@ public interface BrowserContext {
|
||||
*/
|
||||
Page newPage();
|
||||
/**
|
||||
* Returns all open pages in the context. Non visible pages, such as {@code "background_page"}, will not be listed here. You can find them using {@code chromiumBrowserContext.backgroundPages()}.
|
||||
* Returns all open pages in the context. Non visible pages, such as {@code "background_page"}, will not be listed here. You can
|
||||
* <p>
|
||||
* find them using [{@code method: ChromiumBrowserContext.backgroundPages}].
|
||||
*/
|
||||
List<Page> pages();
|
||||
void route(String url, Consumer<Route> handler);
|
||||
void route(Pattern url, Consumer<Route> handler);
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* <p>
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* or the same snippet using a regex pattern instead:
|
||||
* <p>
|
||||
* Page routes (set up with {@code page.route(url, handler)}) take precedence over browser context routes when request matches both handlers.
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE</strong> Enabling routing disables http cache.
|
||||
* @param url A glob pattern, regex pattern or predicate receiving URL to match while routing.
|
||||
* Page routes (set up with [{@code method: Page.route}]) take precedence over browser context routes when request matches both
|
||||
* <p>
|
||||
* handlers.
|
||||
* <p>
|
||||
* > <strong>NOTE</strong> Enabling routing disables http cache.
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing.
|
||||
* @param handler handler function to route the request.
|
||||
*/
|
||||
void route(Predicate<String> url, Consumer<Route> handler);
|
||||
/**
|
||||
* This setting will change the default maximum navigation time for the following methods and related shortcuts:
|
||||
* <p>
|
||||
* {@code page.goBack([options])}
|
||||
* - [{@code method: Page.goBack}]
|
||||
* <p>
|
||||
* {@code page.goForward([options])}
|
||||
* - [{@code method: Page.goForward}]
|
||||
* <p>
|
||||
* {@code page.goto(url[, options])}
|
||||
* - [{@code method: Page.goto}]
|
||||
* <p>
|
||||
* {@code page.reload([options])}
|
||||
* - [{@code method: Page.reload}]
|
||||
* <p>
|
||||
* {@code page.setContent(html[, options])}
|
||||
* - [{@code method: Page.setContent}]
|
||||
* <p>
|
||||
* {@code page.waitForNavigation([options])}
|
||||
* - [{@code method: Page.waitForNavigation}]
|
||||
* <p>
|
||||
*
|
||||
* > <strong>NOTE</strong> [{@code method: Page.setDefaultNavigationTimeout}] and [{@code method: Page.setDefaultTimeout}] take priority over
|
||||
* <p>
|
||||
* <strong>NOTE</strong> {@code page.setDefaultNavigationTimeout(timeout)} and {@code page.setDefaultTimeout(timeout)} take priority over {@code browserContext.setDefaultNavigationTimeout(timeout)}.
|
||||
* [{@code method: BrowserContext.setDefaultNavigationTimeout}].
|
||||
* @param timeout Maximum navigation time in milliseconds
|
||||
*/
|
||||
void setDefaultNavigationTimeout(int timeout);
|
||||
/**
|
||||
* This setting will change the default maximum time for all the methods accepting {@code timeout} option.
|
||||
* <p>
|
||||
* <strong>NOTE</strong> {@code page.setDefaultNavigationTimeout(timeout)}, {@code page.setDefaultTimeout(timeout)} and {@code browserContext.setDefaultNavigationTimeout(timeout)} take priority over {@code browserContext.setDefaultTimeout(timeout)}.
|
||||
* > <strong>NOTE</strong> [{@code method: Page.setDefaultNavigationTimeout}], [{@code method: Page.setDefaultTimeout}] and
|
||||
* <p>
|
||||
* [{@code method: BrowserContext.setDefaultNavigationTimeout}] take priority over [{@code method: BrowserContext.setDefaultTimeout}].
|
||||
* @param timeout Maximum time in milliseconds
|
||||
*/
|
||||
void setDefaultTimeout(int timeout);
|
||||
/**
|
||||
* The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged with page-specific extra HTTP headers set with {@code page.setExtraHTTPHeaders(headers)}. If page overrides a particular header, page-specific header value will be used instead of the browser context header value.
|
||||
* The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
||||
* <p>
|
||||
* <strong>NOTE</strong> {@code browserContext.setExtraHTTPHeaders} does not guarantee the order of headers in the outgoing requests.
|
||||
* with page-specific extra HTTP headers set with [{@code method: Page.setExtraHTTPHeaders}]. If page overrides a particular
|
||||
* <p>
|
||||
* header, page-specific header value will be used instead of the browser context header value.
|
||||
* <p>
|
||||
* > <strong>NOTE</strong> {@code browserContext.setExtraHTTPHeaders} does not guarantee the order of headers in the outgoing requests.
|
||||
* @param headers An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
*/
|
||||
void setExtraHTTPHeaders(Map<String, String> headers);
|
||||
@@ -407,7 +479,9 @@ public interface BrowserContext {
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE</strong> Consider using {@code browserContext.grantPermissions(permissions[, options])} to grant permissions for the browser context pages to read its geolocation.
|
||||
* > <strong>NOTE</strong> Consider using [{@code method: BrowserContext.grantPermissions}] to grant permissions for the browser context pages
|
||||
* <p>
|
||||
* to read its geolocation.
|
||||
*/
|
||||
void setGeolocation(Geolocation geolocation);
|
||||
/**
|
||||
@@ -428,9 +502,12 @@ public interface BrowserContext {
|
||||
void unroute(String url, Consumer<Route> handler);
|
||||
void unroute(Pattern url, Consumer<Route> handler);
|
||||
/**
|
||||
* Removes a route created with {@code browserContext.route(url, handler)}. When {@code handler} is not specified, removes all routes for the {@code url}.
|
||||
* @param url A glob pattern, regex pattern or predicate receiving URL used to register a routing with {@code browserContext.route(url, handler)}.
|
||||
* @param handler Optional handler function used to register a routing with {@code browserContext.route(url, handler)}.
|
||||
* Removes a route created with [{@code method: BrowserContext.route}]. When {@code handler} is not specified, removes all routes for
|
||||
* <p>
|
||||
* the {@code url}.
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with
|
||||
* [{@code method: BrowserContext.route}].
|
||||
* @param handler Optional handler function used to register a routing with [{@code method: BrowserContext.route}].
|
||||
*/
|
||||
void unroute(Predicate<String> url, Consumer<Route> handler);
|
||||
default Deferred<Event<EventType>> futureEvent(EventType event) {
|
||||
@@ -442,7 +519,11 @@ public interface BrowserContext {
|
||||
return futureEvent(event, options);
|
||||
}
|
||||
/**
|
||||
* Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
||||
* Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
||||
* <p>
|
||||
* value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* @param event Event name, same one would pass into {@code browserContext.on(event)}.
|
||||
|
||||
@@ -20,14 +20,19 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a typical example of using Playwright to drive automation:
|
||||
* BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
|
||||
* <p>
|
||||
* typical example of using Playwright to drive automation:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface BrowserType {
|
||||
class LaunchOptions {
|
||||
public class Proxy {
|
||||
/**
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or
|
||||
* {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
*/
|
||||
public String server;
|
||||
/**
|
||||
@@ -67,38 +72,43 @@ public interface BrowserType {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to {@code true} unless the {@code devtools} option is {@code true}.
|
||||
*/
|
||||
public Boolean headless;
|
||||
/**
|
||||
* Path to a browser executable to run instead of the bundled one. If {@code executablePath} is a relative path, then it is resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox or WebKit, use at your own risk.
|
||||
*/
|
||||
public Path executablePath;
|
||||
/**
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found here.
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found
|
||||
* [here](http://peter.sh/experiments/chromium-command-line-switches/).
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
* If {@code true}, Playwright does not pass its own configurations args and only uses the ones from {@code args}. If an array is given, then filters out the given default arguments. Dangerous option; use with care. Defaults to {@code false}.
|
||||
*/
|
||||
public List<String> ignoreDefaultArgs;
|
||||
public Boolean ignoreAllDefaultArgs;
|
||||
/**
|
||||
* Network proxy settings.
|
||||
*/
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
|
||||
*/
|
||||
public Path downloadsPath;
|
||||
/**
|
||||
* Enable Chromium sandboxing. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean chromiumSandbox;
|
||||
/**
|
||||
* Firefox user preferences. Learn more about the Firefox user preferences at {@code about:config}.
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code headless}
|
||||
* option will be set {@code false}.
|
||||
*/
|
||||
public String firefoxUserPrefs;
|
||||
public Boolean devtools;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed.
|
||||
*/
|
||||
public Path downloadsPath;
|
||||
/**
|
||||
* Specify environment variables that will be visible to the browser. Defaults to {@code process.env}.
|
||||
*/
|
||||
public Map<String, String> env;
|
||||
/**
|
||||
* Path to a browser executable to run instead of the bundled one. If {@code executablePath} is a relative path, then it is
|
||||
* resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox
|
||||
* or WebKit, use at your own risk.
|
||||
*/
|
||||
public Path executablePath;
|
||||
/**
|
||||
* Firefox user preferences. Learn more about the Firefox user preferences at
|
||||
* [{@code about:config}](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
|
||||
*/
|
||||
public Map<String, Object> firefoxUserPrefs;
|
||||
/**
|
||||
* Close the browser process on SIGHUP. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean handleSIGHUP;
|
||||
/**
|
||||
* Close the browser process on Ctrl-C. Defaults to {@code true}.
|
||||
*/
|
||||
@@ -108,36 +118,74 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean handleSIGTERM;
|
||||
/**
|
||||
* Close the browser process on SIGHUP. Defaults to {@code true}.
|
||||
* Whether to run browser in headless mode. More details for
|
||||
* [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and
|
||||
* [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to {@code true} unless the
|
||||
* {@code devtools} option is {@code true}.
|
||||
*/
|
||||
public Boolean handleSIGHUP;
|
||||
public Boolean headless;
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
|
||||
* If {@code true}, Playwright does not pass its own configurations args and only uses the ones from {@code args}. If an array is
|
||||
* given, then filters out the given default arguments. Dangerous option; use with care. Defaults to {@code false}.
|
||||
*/
|
||||
public Integer timeout;
|
||||
public List<String> ignoreDefaultArgs;
|
||||
public Boolean ignoreAllDefaultArgs;
|
||||
/**
|
||||
* Specify environment variables that will be visible to the browser. Defaults to {@code process.env}.
|
||||
* Network proxy settings.
|
||||
*/
|
||||
public Map<String, String> env;
|
||||
/**
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code headless} option will be set {@code false}.
|
||||
*/
|
||||
public Boolean devtools;
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
|
||||
*/
|
||||
public Integer slowMo;
|
||||
public Double slowMo;
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
|
||||
* disable timeout.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
public LaunchOptions withHeadless(Boolean headless) {
|
||||
this.headless = headless;
|
||||
public LaunchOptions withArgs(List<String> args) {
|
||||
this.args = args;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withChromiumSandbox(Boolean chromiumSandbox) {
|
||||
this.chromiumSandbox = chromiumSandbox;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withDevtools(Boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withDownloadsPath(Path downloadsPath) {
|
||||
this.downloadsPath = downloadsPath;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withEnv(Map<String, String> env) {
|
||||
this.env = env;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withExecutablePath(Path executablePath) {
|
||||
this.executablePath = executablePath;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withArgs(List<String> args) {
|
||||
this.args = args;
|
||||
public LaunchOptions withFirefoxUserPrefs(Map<String, Object> firefoxUserPrefs) {
|
||||
this.firefoxUserPrefs = firefoxUserPrefs;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withHandleSIGHUP(Boolean handleSIGHUP) {
|
||||
this.handleSIGHUP = handleSIGHUP;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withHandleSIGINT(Boolean handleSIGINT) {
|
||||
this.handleSIGINT = handleSIGINT;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withHandleSIGTERM(Boolean handleSIGTERM) {
|
||||
this.handleSIGTERM = handleSIGTERM;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withHeadless(Boolean headless) {
|
||||
this.headless = headless;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withIgnoreDefaultArgs(List<String> argumentNames) {
|
||||
@@ -152,51 +200,20 @@ public interface BrowserType {
|
||||
this.proxy = new Proxy();
|
||||
return this.proxy;
|
||||
}
|
||||
public LaunchOptions withDownloadsPath(Path downloadsPath) {
|
||||
this.downloadsPath = downloadsPath;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withChromiumSandbox(Boolean chromiumSandbox) {
|
||||
this.chromiumSandbox = chromiumSandbox;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withFirefoxUserPrefs(String firefoxUserPrefs) {
|
||||
this.firefoxUserPrefs = firefoxUserPrefs;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withHandleSIGINT(Boolean handleSIGINT) {
|
||||
this.handleSIGINT = handleSIGINT;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withHandleSIGTERM(Boolean handleSIGTERM) {
|
||||
this.handleSIGTERM = handleSIGTERM;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withHandleSIGHUP(Boolean handleSIGHUP) {
|
||||
this.handleSIGHUP = handleSIGHUP;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withEnv(Map<String, String> env) {
|
||||
this.env = env;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withDevtools(Boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withSlowMo(Integer slowMo) {
|
||||
public LaunchOptions withSlowMo(Double slowMo) {
|
||||
this.slowMo = slowMo;
|
||||
return this;
|
||||
}
|
||||
public LaunchOptions withTimeout(Double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class LaunchPersistentContextOptions {
|
||||
public class Proxy {
|
||||
/**
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
* Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example {@code http://myproxy.com:3128} or
|
||||
* {@code socks5://myproxy.com:3128}. Short form {@code myproxy.com:3128} is considered an HTTP proxy.
|
||||
*/
|
||||
public String server;
|
||||
/**
|
||||
@@ -291,7 +308,9 @@ public interface BrowserType {
|
||||
*/
|
||||
public Path dir;
|
||||
/**
|
||||
* Optional dimensions of the recorded videos. If not specified the size will be equal to {@code viewport}. If {@code viewport} is not configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary to fit the specified size.
|
||||
* Optional dimensions of the recorded videos. If not specified the size will be equal to {@code viewport}. If {@code viewport} is not
|
||||
* configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary
|
||||
* to fit the specified size.
|
||||
*/
|
||||
public Size size;
|
||||
|
||||
@@ -311,34 +330,60 @@ public interface BrowserType {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to {@code true} unless the {@code devtools} option is {@code true}.
|
||||
* Whether to automatically download all the attachments. Defaults to {@code false} where all the downloads are canceled.
|
||||
*/
|
||||
public Boolean headless;
|
||||
public Boolean acceptDownloads;
|
||||
/**
|
||||
* Path to a browser executable to run instead of the bundled one. If {@code executablePath} is a relative path, then it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk.
|
||||
*/
|
||||
public Path executablePath;
|
||||
/**
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found here.
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found
|
||||
* [here](http://peter.sh/experiments/chromium-command-line-switches/).
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
* If {@code true}, then do not use any of the default arguments. If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to {@code false}.
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public List<String> ignoreDefaultArgs;
|
||||
public Boolean ignoreAllDefaultArgs;
|
||||
/**
|
||||
* Network proxy settings.
|
||||
*/
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
|
||||
*/
|
||||
public Path downloadsPath;
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* Enable Chromium sandboxing. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean chromiumSandbox;
|
||||
/**
|
||||
* Emulates {@code 'prefers-colors-scheme'} media feature, supported values are {@code 'light'}, {@code 'dark'}, {@code 'no-preference'}. See
|
||||
* [{@code method: Page.emulateMedia}] for more details. Defaults to '{@code light}'.
|
||||
*/
|
||||
public ColorScheme colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code headless}
|
||||
* option will be set {@code false}.
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed.
|
||||
*/
|
||||
public Path downloadsPath;
|
||||
/**
|
||||
* Specify environment variables that will be visible to the browser. Defaults to {@code process.env}.
|
||||
*/
|
||||
public Map<String, String> env;
|
||||
/**
|
||||
* Path to a browser executable to run instead of the bundled one. If {@code executablePath} is a relative path, then it is
|
||||
* resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled
|
||||
* Chromium, Firefox or WebKit, use at your own risk.
|
||||
*/
|
||||
public Path executablePath;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Close the browser process on SIGHUP. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean handleSIGHUP;
|
||||
/**
|
||||
* Close the browser process on Ctrl-C. Defaults to {@code true}.
|
||||
*/
|
||||
@@ -348,129 +393,142 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean handleSIGTERM;
|
||||
/**
|
||||
* Close the browser process on SIGHUP. Defaults to {@code true}.
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public Boolean handleSIGHUP;
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
|
||||
* Whether to run browser in headless mode. More details for
|
||||
* [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and
|
||||
* [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to {@code true} unless the
|
||||
* {@code devtools} option is {@code true}.
|
||||
*/
|
||||
public Integer timeout;
|
||||
public Boolean headless;
|
||||
/**
|
||||
* Specify environment variables that will be visible to the browser. Defaults to {@code process.env}.
|
||||
* Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
|
||||
*/
|
||||
public Map<String, String> env;
|
||||
public BrowserContext.HTTPCredentials httpCredentials;
|
||||
/**
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code headless} option will be set {@code false}.
|
||||
* If {@code true}, then do not use any of the default arguments. If an array is given, then filter out the given default
|
||||
* arguments. Dangerous option; use with care. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
* Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. Defaults to 0.
|
||||
*/
|
||||
public Integer slowMo;
|
||||
/**
|
||||
* Whether to automatically download all the attachments. Defaults to {@code false} where all the downloads are canceled.
|
||||
*/
|
||||
public Boolean acceptDownloads;
|
||||
public List<String> ignoreDefaultArgs;
|
||||
public Boolean ignoreAllDefaultArgs;
|
||||
/**
|
||||
* Whether to ignore HTTPS errors during navigation. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default viewport.
|
||||
*/
|
||||
public Page.Viewport viewport;
|
||||
/**
|
||||
* Specific user agent to use in this context.
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public Integer deviceScaleFactor;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Changes the timezone of the context. See ICU’s {@code metaZones.txt} for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@code browserContext.grantPermissions(permissions[, options])} for more details.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* Credentials for HTTP authentication.
|
||||
* A list of permissions to grant to all pages in this context. See [{@code method: BrowserContext.grantPermissions}] for more
|
||||
* details.
|
||||
*/
|
||||
public BrowserContext.HTTPCredentials httpCredentials;
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Emulates {@code 'prefers-colors-scheme'} media feature, supported values are {@code 'light'}, {@code 'dark'}, {@code 'no-preference'}. See {@code page.emulateMedia(params)} for more details. Defaults to '{@code light}'.
|
||||
* Network proxy settings.
|
||||
*/
|
||||
public ColorScheme colorScheme;
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* Enables HAR recording for all pages into {@code recordHar.path} file. If not specified, the HAR is not recorded. Make sure to await {@code browserContext.close()} for the HAR to be saved.
|
||||
* Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into {@code recordHar.path} file. If not
|
||||
* specified, the HAR is not recorded. Make sure to await [{@code method: BrowserContext.close}] for the HAR to be saved.
|
||||
*/
|
||||
public RecordHar recordHar;
|
||||
/**
|
||||
* Enables video recording for all pages into {@code recordVideo.dir} directory. If not specified videos are not recorded. Make sure to await {@code browserContext.close()} for videos to be saved.
|
||||
* Enables video recording for all pages into {@code recordVideo.dir} directory. If not specified videos are not recorded. Make
|
||||
* sure to await [{@code method: BrowserContext.close}] for videos to be saved.
|
||||
*/
|
||||
public RecordVideo recordVideo;
|
||||
/**
|
||||
* Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
|
||||
* Defaults to 0.
|
||||
*/
|
||||
public Double slowMo;
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
|
||||
* disable timeout.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
* Changes the timezone of the context. See
|
||||
* [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
|
||||
* for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
* Specific user agent to use in this context.
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default viewport.
|
||||
*/
|
||||
public Page.Viewport viewport;
|
||||
|
||||
public LaunchPersistentContextOptions withHeadless(Boolean headless) {
|
||||
this.headless = headless;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withExecutablePath(Path executablePath) {
|
||||
this.executablePath = executablePath;
|
||||
public LaunchPersistentContextOptions withAcceptDownloads(Boolean acceptDownloads) {
|
||||
this.acceptDownloads = acceptDownloads;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withArgs(List<String> args) {
|
||||
this.args = args;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withIgnoreDefaultArgs(List<String> argumentNames) {
|
||||
this.ignoreDefaultArgs = argumentNames;
|
||||
public LaunchPersistentContextOptions withBypassCSP(Boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withIgnoreAllDefaultArgs(boolean ignore) {
|
||||
this.ignoreAllDefaultArgs = ignore;
|
||||
public LaunchPersistentContextOptions withChromiumSandbox(Boolean chromiumSandbox) {
|
||||
this.chromiumSandbox = chromiumSandbox;
|
||||
return this;
|
||||
}
|
||||
public Proxy setProxy() {
|
||||
this.proxy = new Proxy();
|
||||
return this.proxy;
|
||||
public LaunchPersistentContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withDeviceScaleFactor(Double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withDevtools(Boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withDownloadsPath(Path downloadsPath) {
|
||||
this.downloadsPath = downloadsPath;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withChromiumSandbox(Boolean chromiumSandbox) {
|
||||
this.chromiumSandbox = chromiumSandbox;
|
||||
public LaunchPersistentContextOptions withEnv(Map<String, String> env) {
|
||||
this.env = env;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withExecutablePath(Path executablePath) {
|
||||
this.executablePath = executablePath;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withGeolocation(Geolocation geolocation) {
|
||||
this.geolocation = geolocation;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withHandleSIGHUP(Boolean handleSIGHUP) {
|
||||
this.handleSIGHUP = handleSIGHUP;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withHandleSIGINT(Boolean handleSIGINT) {
|
||||
@@ -481,94 +539,54 @@ public interface BrowserType {
|
||||
this.handleSIGTERM = handleSIGTERM;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withHandleSIGHUP(Boolean handleSIGHUP) {
|
||||
this.handleSIGHUP = handleSIGHUP;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withEnv(Map<String, String> env) {
|
||||
this.env = env;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withDevtools(Boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withSlowMo(Integer slowMo) {
|
||||
this.slowMo = slowMo;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withAcceptDownloads(Boolean acceptDownloads) {
|
||||
this.acceptDownloads = acceptDownloads;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
|
||||
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withBypassCSP(Boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withDeviceScaleFactor(Integer deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withIsMobile(Boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withHasTouch(Boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withGeolocation(Geolocation geolocation) {
|
||||
this.geolocation = geolocation;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withOffline(Boolean offline) {
|
||||
this.offline = offline;
|
||||
public LaunchPersistentContextOptions withHeadless(Boolean headless) {
|
||||
this.headless = headless;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new BrowserContext.HTTPCredentials(username, password);
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
public LaunchPersistentContextOptions withIgnoreDefaultArgs(List<String> argumentNames) {
|
||||
this.ignoreDefaultArgs = argumentNames;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withIgnoreAllDefaultArgs(boolean ignore) {
|
||||
this.ignoreAllDefaultArgs = ignore;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
|
||||
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withIsMobile(Boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withOffline(Boolean offline) {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
public Proxy setProxy() {
|
||||
this.proxy = new Proxy();
|
||||
return this.proxy;
|
||||
}
|
||||
public RecordHar setRecordHar() {
|
||||
this.recordHar = new RecordHar();
|
||||
return this.recordHar;
|
||||
@@ -577,6 +595,26 @@ public interface BrowserType {
|
||||
this.recordVideo = new RecordVideo();
|
||||
return this.recordVideo;
|
||||
}
|
||||
public LaunchPersistentContextOptions withSlowMo(Double slowMo) {
|
||||
this.slowMo = slowMo;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withTimeout(Double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A path where Playwright expects to find a bundled browser executable.
|
||||
@@ -592,13 +630,33 @@ public interface BrowserType {
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* **Chromium-only** Playwright can also be used to control the Chrome browser, but it works best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use {@code executablePath} option with extreme caution.
|
||||
* > **Chromium-only** Playwright can also be used to control the Chrome browser, but it works best with the version of
|
||||
* <p>
|
||||
* If Google Chrome (rather than Chromium) is preferred, a Chrome Canary or Dev Channel build is suggested.
|
||||
* Chromium it is bundled with. There is no guarantee it will work with any other version. Use {@code executablePath} option with
|
||||
* <p>
|
||||
* In {@code browserType.launch([options])} above, any mention of Chromium also applies to Chrome.
|
||||
* extreme caution.
|
||||
* <p>
|
||||
* See {@code this article} for a description of the differences between Chromium and Chrome. {@code This article} describes some differences for Linux users.
|
||||
* >
|
||||
* <p>
|
||||
* > If Google Chrome (rather than Chromium) is preferred, a
|
||||
* <p>
|
||||
* [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
|
||||
* <p>
|
||||
* [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
|
||||
* <p>
|
||||
* >
|
||||
* <p>
|
||||
* > In [{@code method: BrowserType.launch}] above, any mention of Chromium also applies to Chrome.
|
||||
* <p>
|
||||
* >
|
||||
* <p>
|
||||
* > See [{@code this article}](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for
|
||||
* <p>
|
||||
* a description of the differences between Chromium and Chrome.
|
||||
* <p>
|
||||
* [{@code This article}](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
|
||||
* <p>
|
||||
* describes some differences for Linux users.
|
||||
*/
|
||||
Browser launch(LaunchOptions options);
|
||||
default BrowserContext launchPersistentContext(Path userDataDir) {
|
||||
@@ -607,8 +665,12 @@ public interface BrowserType {
|
||||
/**
|
||||
* Returns the persistent browser context instance.
|
||||
* <p>
|
||||
* Launches browser that uses persistent storage located at {@code userDataDir} and returns the only context. Closing this context will automatically close the browser.
|
||||
* @param userDataDir Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for Chromium and Firefox.
|
||||
* Launches browser that uses persistent storage located at {@code userDataDir} and returns the only context. Closing this
|
||||
* <p>
|
||||
* context will automatically close the browser.
|
||||
* @param userDataDir Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for
|
||||
* [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) and
|
||||
* [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile).
|
||||
*/
|
||||
BrowserContext launchPersistentContext(Path userDataDir, LaunchPersistentContextOptions options);
|
||||
/**
|
||||
|
||||
@@ -19,12 +19,12 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* ConsoleMessage objects are dispatched by page via the page.on('console') event.
|
||||
* {@code ConsoleMessage} objects are dispatched by page via the [{@code event: Page.console}] event.
|
||||
*/
|
||||
public interface ConsoleMessage {
|
||||
class Location {
|
||||
/**
|
||||
* URL of the resource if available, otherwise empty string.
|
||||
* URL of the resource.
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
@@ -50,7 +50,11 @@ public interface ConsoleMessage {
|
||||
Location location();
|
||||
String text();
|
||||
/**
|
||||
* One of the following values: {@code 'log'}, {@code 'debug'}, {@code 'info'}, {@code 'error'}, {@code 'warning'}, {@code 'dir'}, {@code 'dirxml'}, {@code 'table'}, {@code 'trace'}, {@code 'clear'}, {@code 'startGroup'}, {@code 'startGroupCollapsed'}, {@code 'endGroup'}, {@code 'assert'}, {@code 'profile'}, {@code 'profileEnd'}, {@code 'count'}, {@code 'timeEnd'}.
|
||||
* One of the following values: {@code 'log'}, {@code 'debug'}, {@code 'info'}, {@code 'error'}, {@code 'warning'}, {@code 'dir'}, {@code 'dirxml'}, {@code 'table'},
|
||||
* <p>
|
||||
* {@code 'trace'}, {@code 'clear'}, {@code 'startGroup'}, {@code 'startGroupCollapsed'}, {@code 'endGroup'}, {@code 'assert'}, {@code 'profile'}, {@code 'profileEnd'},
|
||||
* <p>
|
||||
* {@code 'count'}, {@code 'timeEnd'}.
|
||||
*/
|
||||
String type();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface DeviceDescriptor {
|
||||
}
|
||||
Viewport viewport();
|
||||
String userAgent();
|
||||
int deviceScaleFactor();
|
||||
double deviceScaleFactor();
|
||||
boolean isMobile();
|
||||
boolean hasTouch();
|
||||
BrowserType defaultBrowserType();
|
||||
|
||||
@@ -19,7 +19,10 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Dialog objects are dispatched by page via the page.on('dialog') event.
|
||||
* {@code Dialog} objects are dispatched by page via the [{@code event: Page.dialog}] event.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface Dialog {
|
||||
enum Type { ALERT, BEFOREUNLOAD, CONFIRM, PROMPT }
|
||||
|
||||
@@ -21,15 +21,21 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Download objects are dispatched by page via the page.on('download') event.
|
||||
* {@code Download} objects are dispatched by page via the [{@code event: Page.download}] event.
|
||||
* <p>
|
||||
* All the downloaded files belonging to the browser context are deleted when the browser context is closed. All downloaded files are deleted when the browser closes.
|
||||
* All the downloaded files belonging to the browser context are deleted when the browser context is closed. All downloaded
|
||||
* <p>
|
||||
* files are deleted when the browser closes.
|
||||
* <p>
|
||||
* Download event is emitted once the download starts. Download path becomes available once download completes:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE</strong> Browser context **must** be created with the {@code acceptDownloads} set to {@code true} when user needs access to the downloaded content. If {@code acceptDownloads} is not set or set to {@code false}, download events are emitted, but the actual download is not performed and user has no access to the downloaded files.
|
||||
* > <strong>NOTE</strong> Browser context **must** be created with the {@code acceptDownloads} set to {@code true} when user needs access to the
|
||||
* <p>
|
||||
* downloaded content. If {@code acceptDownloads} is not set or set to {@code false}, download events are emitted, but the actual
|
||||
* <p>
|
||||
* download is not performed and user has no access to the downloaded files.
|
||||
*/
|
||||
public interface Download {
|
||||
/**
|
||||
@@ -54,7 +60,13 @@ public interface Download {
|
||||
*/
|
||||
void saveAs(Path path);
|
||||
/**
|
||||
* Returns suggested filename for this download. It is typically computed by the browser from the {@code Content-Disposition} response header or the {@code download} attribute. See the spec on whatwg. Different browsers can use different logic for computing it.
|
||||
* Returns suggested filename for this download. It is typically computed by the browser from the
|
||||
* <p>
|
||||
* [{@code Content-Disposition}](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) response header
|
||||
* <p>
|
||||
* or the {@code download} attribute. See the spec on [whatwg](https://html.spec.whatwg.org/#downloading-resources). Different
|
||||
* <p>
|
||||
* browsers can use different logic for computing it.
|
||||
*/
|
||||
String suggestedFilename();
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,9 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* FileChooser objects are dispatched by the page in the page.on('filechooser') event.
|
||||
* {@code FileChooser} objects are dispatched by the page in the [{@code event: Page.filechooser}] event.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface FileChooser {
|
||||
@@ -38,19 +40,22 @@ public interface FileChooser {
|
||||
|
||||
class SetFilesOptions {
|
||||
/**
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to {@code false}.
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
|
||||
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
|
||||
* inaccessible pages. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by using the {@code browserContext.setDefaultTimeout(timeout)} or {@code page.setDefaultTimeout(timeout)} methods.
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by
|
||||
* using the [{@code method: BrowserContext.setDefaultTimeout}] or [{@code method: Page.setDefaultTimeout}] methods.
|
||||
*/
|
||||
public Integer timeout;
|
||||
public Double timeout;
|
||||
|
||||
public SetFilesOptions withNoWaitAfter(Boolean noWaitAfter) {
|
||||
this.noWaitAfter = noWaitAfter;
|
||||
return this;
|
||||
}
|
||||
public SetFilesOptions withTimeout(Integer timeout) {
|
||||
public SetFilesOptions withTimeout(Double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
@@ -75,7 +80,9 @@ public interface FileChooser {
|
||||
default void setFiles(FileChooser.FilePayload file, SetFilesOptions options) { setFiles(new FileChooser.FilePayload[]{ file }, options); }
|
||||
default void setFiles(FileChooser.FilePayload[] files) { setFiles(files, null); }
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then they are resolved relative to the the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* <p>
|
||||
* they are resolved relative to the the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
void setFiles(FileChooser.FilePayload[] files, SetFilesOptions options);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,15 +19,25 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* JSHandle represents an in-page JavaScript object. JSHandles can be created with the {@code page.evaluateHandle(pageFunction[, arg])} method.
|
||||
* JSHandle represents an in-page JavaScript object. JSHandles can be created with the [{@code method: Page.evaluateHandle}]
|
||||
* <p>
|
||||
* JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with {@code jsHandle.dispose()}. JSHandles are auto-disposed when their origin frame gets navigated or the parent context gets destroyed.
|
||||
* method.
|
||||
* <p>
|
||||
* JSHandle instances can be used as an argument in {@code page.$eval(selector, pageFunction[, arg])}, {@code page.evaluate(pageFunction[, arg])} and {@code page.evaluateHandle(pageFunction[, arg])} methods.
|
||||
*
|
||||
* <p>
|
||||
* JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with
|
||||
* <p>
|
||||
* [{@code method: JSHandle.dispose}]. JSHandles are auto-disposed when their origin frame gets navigated or the parent context
|
||||
* <p>
|
||||
* gets destroyed.
|
||||
* <p>
|
||||
* JSHandle instances can be used as an argument in [{@code method: Page.$eval}], [{@code method: Page.evaluate}] and
|
||||
* <p>
|
||||
* [{@code method: Page.evaluateHandle}] methods.
|
||||
*/
|
||||
public interface JSHandle {
|
||||
/**
|
||||
* Returns either {@code null} or the object handle itself, if the object handle is an instance of ElementHandle.
|
||||
* Returns either {@code null} or the object handle itself, if the object handle is an instance of {@code ElementHandle}.
|
||||
*/
|
||||
ElementHandle asElement();
|
||||
/**
|
||||
@@ -42,11 +52,15 @@ public interface JSHandle {
|
||||
* <p>
|
||||
* This method passes this handle as the first argument to {@code pageFunction}.
|
||||
* <p>
|
||||
* If {@code pageFunction} returns a Promise, then {@code handle.evaluate} would wait for the promise to resolve and return its value.
|
||||
* If {@code pageFunction} returns a [Promise], then {@code handle.evaluate} would wait for the promise to resolve and return its
|
||||
* <p>
|
||||
* value.
|
||||
* <p>
|
||||
* Examples:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* @param pageFunction Function to be evaluated in browser context
|
||||
* @param arg Optional argument to pass to {@code pageFunction}
|
||||
*/
|
||||
@@ -59,11 +73,15 @@ public interface JSHandle {
|
||||
* <p>
|
||||
* This method passes this handle as the first argument to {@code pageFunction}.
|
||||
* <p>
|
||||
* The only difference between {@code jsHandle.evaluate} and {@code jsHandle.evaluateHandle} is that {@code jsHandle.evaluateHandle} returns in-page object (JSHandle).
|
||||
* The only difference between {@code jsHandle.evaluate} and {@code jsHandle.evaluateHandle} is that {@code jsHandle.evaluateHandle} returns
|
||||
* <p>
|
||||
* If the function passed to the {@code jsHandle.evaluateHandle} returns a Promise, then {@code jsHandle.evaluateHandle} would wait for the promise to resolve and return its value.
|
||||
* in-page object (JSHandle).
|
||||
* <p>
|
||||
* See {@code page.evaluateHandle(pageFunction[, arg])} for more details.
|
||||
* If the function passed to the {@code jsHandle.evaluateHandle} returns a [Promise], then {@code jsHandle.evaluateHandle} would wait
|
||||
* <p>
|
||||
* for the promise to resolve and return its value.
|
||||
* <p>
|
||||
* See [{@code method: Page.evaluateHandle}] for more details.
|
||||
* @param pageFunction Function to be evaluated
|
||||
* @param arg Optional argument to pass to {@code pageFunction}
|
||||
*/
|
||||
@@ -71,6 +89,8 @@ public interface JSHandle {
|
||||
/**
|
||||
* The method returns a map with **own property names** as keys and JSHandle instances for the property values.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
Map<String, JSHandle> getProperties();
|
||||
/**
|
||||
@@ -81,7 +101,9 @@ public interface JSHandle {
|
||||
/**
|
||||
* Returns a JSON representation of the object. If the object has a {@code toJSON} function, it **will not be called**.
|
||||
* <p>
|
||||
* <strong>NOTE</strong> The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an error if the object has circular references.
|
||||
* > <strong>NOTE</strong> The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an
|
||||
* <p>
|
||||
* error if the object has circular references.
|
||||
*/
|
||||
Object jsonValue();
|
||||
}
|
||||
|
||||
@@ -19,12 +19,22 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Keyboard provides an api for managing a virtual keyboard. The high level api is {@code keyboard.type(text[, options])}, which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.
|
||||
* Keyboard provides an api for managing a virtual keyboard. The high level api is [{@code method: Keyboard.type}], which takes
|
||||
* <p>
|
||||
* For finer control, you can use {@code keyboard.down(key)}, {@code keyboard.up(key)}, and {@code keyboard.insertText(text)} to manually fire events as if they were generated from a real keyboard.
|
||||
* raw characters and generates proper keydown, keypress/input, and keyup events on your page.
|
||||
* <p>
|
||||
* For finer control, you can use [{@code method: Keyboard.down}], [{@code method: Keyboard.up}], and [{@code method: Keyboard.insertText}]
|
||||
* <p>
|
||||
* to manually fire events as if they were generated from a real keyboard.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* An example to trigger select-all with the keyboard
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface Keyboard {
|
||||
enum Modifier { ALT, CONTROL, META, SHIFT }
|
||||
@@ -32,21 +42,35 @@ public interface Keyboard {
|
||||
/**
|
||||
* Dispatches a {@code keydown} event.
|
||||
* <p>
|
||||
* {@code key} can specify the intended keyboardEvent.key value or a single character to generate the text for. A superset of the {@code key} values can be found here. Examples of the keys are:
|
||||
* {@code key} can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
||||
* <p>
|
||||
* {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace}, {@code Tab}, {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp}, etc.
|
||||
* value or a single character to generate the text for. A superset of the {@code key} values can be found
|
||||
* <p>
|
||||
* Following modification shortcuts are also suported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code ShiftLeft}.
|
||||
* [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
||||
* <p>
|
||||
* {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace}, {@code Tab},
|
||||
* <p>
|
||||
* {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp}, etc.
|
||||
* <p>
|
||||
* Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code ShiftLeft}.
|
||||
* <p>
|
||||
* Holding down {@code Shift} will type the text that corresponds to the {@code key} in the upper case.
|
||||
* <p>
|
||||
* If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate different respective texts.
|
||||
* If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate different respective
|
||||
* <p>
|
||||
* If {@code key} is a modifier key, {@code Shift}, {@code Meta}, {@code Control}, or {@code Alt}, subsequent key presses will be sent with that modifier active. To release the modifier key, use {@code keyboard.up(key)}.
|
||||
* texts.
|
||||
* <p>
|
||||
* After the key is pressed once, subsequent calls to {@code keyboard.down(key)} will have repeat set to true. To release the key, use {@code keyboard.up(key)}.
|
||||
* If {@code key} is a modifier key, {@code Shift}, {@code Meta}, {@code Control}, or {@code Alt}, subsequent key presses will be sent with that modifier
|
||||
* <p>
|
||||
* <strong>NOTE</strong> Modifier keys DO influence {@code keyboard.down}. Holding down {@code Shift} will type the text in upper case.
|
||||
* active. To release the modifier key, use [{@code method: Keyboard.up}].
|
||||
* <p>
|
||||
* After the key is pressed once, subsequent calls to [{@code method: Keyboard.down}] will have
|
||||
* <p>
|
||||
* [repeat](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat) set to true. To release the key, use
|
||||
* <p>
|
||||
* [{@code method: Keyboard.up}].
|
||||
* <p>
|
||||
* > <strong>NOTE</strong> Modifier keys DO influence {@code keyboard.down}. Holding down {@code Shift} will type the text in upper case.
|
||||
* @param key Name of the key to press or a character to generate, such as {@code ArrowLeft} or {@code a}.
|
||||
*/
|
||||
void down(String key);
|
||||
@@ -55,7 +79,7 @@ public interface Keyboard {
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE</strong> Modifier keys DO NOT effect {@code keyboard.insertText}. Holding down {@code Shift} will not type the text in upper case.
|
||||
* > <strong>NOTE</strong> Modifier keys DO NOT effect {@code keyboard.insertText}. Holding down {@code Shift} will not type the text in upper case.
|
||||
* @param text Sets input to the specified text value.
|
||||
*/
|
||||
void insertText(String text);
|
||||
@@ -63,19 +87,31 @@ public interface Keyboard {
|
||||
press(key, 0);
|
||||
}
|
||||
/**
|
||||
* {@code key} can specify the intended keyboardEvent.key value or a single character to generate the text for. A superset of the {@code key} values can be found here. Examples of the keys are:
|
||||
* {@code key} can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
||||
* <p>
|
||||
* {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace}, {@code Tab}, {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp}, etc.
|
||||
* value or a single character to generate the text for. A superset of the {@code key} values can be found
|
||||
* <p>
|
||||
* Following modification shortcuts are also suported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code ShiftLeft}.
|
||||
* [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
||||
* <p>
|
||||
* {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace}, {@code Tab},
|
||||
* <p>
|
||||
* {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp}, etc.
|
||||
* <p>
|
||||
* Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code ShiftLeft}.
|
||||
* <p>
|
||||
* Holding down {@code Shift} will type the text that corresponds to the {@code key} in the upper case.
|
||||
* <p>
|
||||
* If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate different respective texts.
|
||||
* If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate different respective
|
||||
* <p>
|
||||
* Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When speficied with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* texts.
|
||||
* <p>
|
||||
* Shortcut for {@code keyboard.down(key)} and {@code keyboard.up(key)}.
|
||||
* Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When speficied with the
|
||||
* <p>
|
||||
* modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* Shortcut for [{@code method: Keyboard.down}] and [{@code method: Keyboard.up}].
|
||||
* @param key Name of the key to press or a character to generate, such as {@code ArrowLeft} or {@code a}.
|
||||
*/
|
||||
void press(String key, int delay);
|
||||
@@ -85,11 +121,11 @@ public interface Keyboard {
|
||||
/**
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
* <p>
|
||||
* To press a special key, like {@code Control} or {@code ArrowDown}, use {@code keyboard.press(key[, options])}.
|
||||
* To press a special key, like {@code Control} or {@code ArrowDown}, use [{@code method: Keyboard.press}].
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE</strong> Modifier keys DO NOT effect {@code keyboard.type}. Holding down {@code Shift} will not type the text in upper case.
|
||||
* > <strong>NOTE</strong> Modifier keys DO NOT effect {@code keyboard.type}. Holding down {@code Shift} will not type the text in upper case.
|
||||
* @param text A text to type into a focused element.
|
||||
*/
|
||||
void type(String text, int delay);
|
||||
|
||||
@@ -21,7 +21,9 @@ import java.util.*;
|
||||
/**
|
||||
* The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
|
||||
* <p>
|
||||
* Every {@code page} object has its own Mouse, accessible with page.mouse.
|
||||
* Every {@code page} object has its own Mouse, accessible with [{@code property: Page.mouse}].
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface Mouse {
|
||||
@@ -33,13 +35,13 @@ public interface Mouse {
|
||||
*/
|
||||
public Button button;
|
||||
/**
|
||||
* defaults to 1. See UIEvent.detail.
|
||||
* defaults to 1. See [UIEvent.detail].
|
||||
*/
|
||||
public Integer clickCount;
|
||||
/**
|
||||
* Time to wait between {@code mousedown} and {@code mouseup} in milliseconds. Defaults to 0.
|
||||
*/
|
||||
public Integer delay;
|
||||
public Double delay;
|
||||
|
||||
public ClickOptions withButton(Button button) {
|
||||
this.button = button;
|
||||
@@ -49,7 +51,7 @@ public interface Mouse {
|
||||
this.clickCount = clickCount;
|
||||
return this;
|
||||
}
|
||||
public ClickOptions withDelay(Integer delay) {
|
||||
public ClickOptions withDelay(Double delay) {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
@@ -62,13 +64,13 @@ public interface Mouse {
|
||||
/**
|
||||
* Time to wait between {@code mousedown} and {@code mouseup} in milliseconds. Defaults to 0.
|
||||
*/
|
||||
public Integer delay;
|
||||
public Double delay;
|
||||
|
||||
public DblclickOptions withButton(Button button) {
|
||||
this.button = button;
|
||||
return this;
|
||||
}
|
||||
public DblclickOptions withDelay(Integer delay) {
|
||||
public DblclickOptions withDelay(Double delay) {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
@@ -79,7 +81,7 @@ public interface Mouse {
|
||||
*/
|
||||
public Button button;
|
||||
/**
|
||||
* defaults to 1. See UIEvent.detail.
|
||||
* defaults to 1. See [UIEvent.detail].
|
||||
*/
|
||||
public Integer clickCount;
|
||||
|
||||
@@ -109,7 +111,7 @@ public interface Mouse {
|
||||
*/
|
||||
public Button button;
|
||||
/**
|
||||
* defaults to 1. See UIEvent.detail.
|
||||
* defaults to 1. See [UIEvent.detail].
|
||||
*/
|
||||
public Integer clickCount;
|
||||
|
||||
@@ -126,14 +128,16 @@ public interface Mouse {
|
||||
click(x, y, null);
|
||||
}
|
||||
/**
|
||||
* Shortcut for {@code mouse.move(x, y[, options])}, {@code mouse.down([options])}, {@code mouse.up([options])}.
|
||||
* Shortcut for [{@code method: Mouse.move}], [{@code method: Mouse.down}], [{@code method: Mouse.up}].
|
||||
*/
|
||||
void click(int x, int y, ClickOptions options);
|
||||
default void dblclick(int x, int y) {
|
||||
dblclick(x, y, null);
|
||||
}
|
||||
/**
|
||||
* Shortcut for {@code mouse.move(x, y[, options])}, {@code mouse.down([options])}, {@code mouse.up([options])}, {@code mouse.down([options])} and {@code mouse.up([options])}.
|
||||
* Shortcut for [{@code method: Mouse.move}], [{@code method: Mouse.down}], [{@code method: Mouse.up}], [{@code method: Mouse.down}] and
|
||||
* <p>
|
||||
* [{@code method: Mouse.up}].
|
||||
*/
|
||||
void dblclick(int x, int y, DblclickOptions options);
|
||||
default void down() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,22 +17,54 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.impl.PlaywrightImpl;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.Map;
|
||||
/**
|
||||
* Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
|
||||
* <p>
|
||||
* to drive automation:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* By default, the {@code playwright} NPM package automatically downloads browser executables during installation. The
|
||||
* <p>
|
||||
* {@code playwright-core} NPM package can be used to skip automatic downloads.
|
||||
*/
|
||||
public interface Playwright {
|
||||
/**
|
||||
* This object can be used to launch or connect to Chromium, returning instances of {@code ChromiumBrowser}.
|
||||
*/
|
||||
BrowserType chromium();
|
||||
/**
|
||||
* Returns a list of devices to be used with [{@code method: Browser.newContext}] or [{@code method: Browser.newPage}]. Actual list of
|
||||
* <p>
|
||||
* devices can be found in
|
||||
* <p>
|
||||
* [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts).
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
Map<String, DeviceDescriptor> devices();
|
||||
/**
|
||||
* This object can be used to launch or connect to Firefox, returning instances of {@code FirefoxBrowser}.
|
||||
*/
|
||||
BrowserType firefox();
|
||||
/**
|
||||
* Selectors can be used to install custom selector engines. See
|
||||
* <p>
|
||||
* [Working with selectors](./selectors.md#working-with-selectors) for more information.
|
||||
*/
|
||||
Selectors selectors();
|
||||
/**
|
||||
* This object can be used to launch or connect to WebKit, returning instances of {@code WebKitBrowser}.
|
||||
*/
|
||||
BrowserType webkit();
|
||||
|
||||
public interface Playwright extends AutoCloseable {
|
||||
static Playwright create() {
|
||||
return PlaywrightImpl.create();
|
||||
}
|
||||
|
||||
BrowserType chromium();
|
||||
BrowserType firefox();
|
||||
BrowserType webkit();
|
||||
|
||||
Map<String, DeviceDescriptor> devices();
|
||||
|
||||
Selectors selectors();
|
||||
|
||||
@Override
|
||||
void close() throws Exception;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,19 +19,25 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Whenever the page sends a request for a network resource the following sequence of events are emitted by Page:
|
||||
* Whenever the page sends a request for a network resource the following sequence of events are emitted by {@code Page}:
|
||||
* <p>
|
||||
* page.on('request') emitted when the request is issued by the page.
|
||||
* - [{@code event: Page.request}] emitted when the request is issued by the page.
|
||||
* <p>
|
||||
* page.on('response') emitted when/if the response status and headers are received for the request.
|
||||
* - [{@code event: Page.response}] emitted when/if the response status and headers are received for the request.
|
||||
* <p>
|
||||
* page.on('requestfinished') emitted when the response body is downloaded and the request is complete.
|
||||
* - [{@code event: Page.requestfinished}] emitted when the response body is downloaded and the request is complete.
|
||||
* <p>
|
||||
* If request fails at some point, then instead of {@code 'requestfinished'} event (and possibly instead of 'response' event), the page.on('requestfailed') event is emitted.
|
||||
* If request fails at some point, then instead of {@code 'requestfinished'} event (and possibly instead of 'response' event),
|
||||
* <p>
|
||||
* <strong>NOTE</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with {@code 'requestfinished'} event.
|
||||
* the [{@code event: Page.requestfailed}] event is emitted.
|
||||
* <p>
|
||||
* If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url.
|
||||
* > <strong>NOTE</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request
|
||||
* <p>
|
||||
* will complete with {@code 'requestfinished'} event.
|
||||
* <p>
|
||||
* If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new
|
||||
* <p>
|
||||
* request is issued to a redirected url.
|
||||
*/
|
||||
public interface Request {
|
||||
class RequestFailure {
|
||||
@@ -51,65 +57,73 @@ public interface Request {
|
||||
/**
|
||||
* Request start time in milliseconds elapsed since January 1, 1970 00:00:00 UTC
|
||||
*/
|
||||
private int startTime;
|
||||
private double startTime;
|
||||
/**
|
||||
* Time immediately before the browser starts the domain name lookup for the resource. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately before the browser starts the domain name lookup for the resource. The value is given in milliseconds
|
||||
* relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int domainLookupStart;
|
||||
private double domainLookupStart;
|
||||
/**
|
||||
* Time immediately after the browser starts the domain name lookup for the resource. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately after the browser starts the domain name lookup for the resource. The value is given in milliseconds
|
||||
* relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int domainLookupEnd;
|
||||
private double domainLookupEnd;
|
||||
/**
|
||||
* Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. The
|
||||
* value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int connectStart;
|
||||
private double connectStart;
|
||||
/**
|
||||
* Time immediately before the browser starts the handshake process to secure the current connection. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately before the browser starts the handshake process to secure the current connection. The value is given in
|
||||
* milliseconds relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int secureConnectionStart;
|
||||
private double secureConnectionStart;
|
||||
/**
|
||||
* Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. The
|
||||
* value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int connectEnd;
|
||||
private double connectEnd;
|
||||
/**
|
||||
* Time immediately before the browser starts requesting the resource from the server, cache, or local resource. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately before the browser starts requesting the resource from the server, cache, or local resource. The value
|
||||
* is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int requestStart;
|
||||
private double requestStart;
|
||||
/**
|
||||
* Time immediately after the browser starts requesting the resource from the server, cache, or local resource. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately after the browser starts requesting the resource from the server, cache, or local resource. The value
|
||||
* is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int responseStart;
|
||||
private double responseStart;
|
||||
/**
|
||||
* Time immediately after the browser receives the last byte of the resource or immediately before the transport connection is closed, whichever comes first. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately after the browser receives the last byte of the resource or immediately before the transport connection
|
||||
* is closed, whichever comes first. The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
private int responseEnd;
|
||||
private double responseEnd;
|
||||
|
||||
public int startTime() {
|
||||
public double startTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
public int domainLookupStart() {
|
||||
public double domainLookupStart() {
|
||||
return this.domainLookupStart;
|
||||
}
|
||||
public int domainLookupEnd() {
|
||||
public double domainLookupEnd() {
|
||||
return this.domainLookupEnd;
|
||||
}
|
||||
public int connectStart() {
|
||||
public double connectStart() {
|
||||
return this.connectStart;
|
||||
}
|
||||
public int secureConnectionStart() {
|
||||
public double secureConnectionStart() {
|
||||
return this.secureConnectionStart;
|
||||
}
|
||||
public int connectEnd() {
|
||||
public double connectEnd() {
|
||||
return this.connectEnd;
|
||||
}
|
||||
public int requestStart() {
|
||||
public double requestStart() {
|
||||
return this.requestStart;
|
||||
}
|
||||
public int responseStart() {
|
||||
public double responseStart() {
|
||||
return this.responseStart;
|
||||
}
|
||||
public int responseEnd() {
|
||||
public double responseEnd() {
|
||||
return this.responseEnd;
|
||||
}
|
||||
}
|
||||
@@ -118,10 +132,12 @@ public interface Request {
|
||||
* <p>
|
||||
* Example of logging of all the failed requests:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
RequestFailure failure();
|
||||
/**
|
||||
* Returns the Frame that initiated this request.
|
||||
* Returns the {@code Frame} that initiated this request.
|
||||
*/
|
||||
Frame frame();
|
||||
/**
|
||||
@@ -147,31 +163,51 @@ public interface Request {
|
||||
/**
|
||||
* Request that was redirected by the server to this one, if any.
|
||||
* <p>
|
||||
* When the server responds with a redirect, Playwright creates a new Request object. The two requests are connected by {@code redirectedFrom()} and {@code redirectedTo()} methods. When multiple server redirects has happened, it is possible to construct the whole redirect chain by repeatedly calling {@code redirectedFrom()}.
|
||||
* When the server responds with a redirect, Playwright creates a new {@code Request} object. The two requests are connected by
|
||||
* <p>
|
||||
* {@code redirectedFrom()} and {@code redirectedTo()} methods. When multiple server redirects has happened, it is possible to
|
||||
* <p>
|
||||
* construct the whole redirect chain by repeatedly calling {@code redirectedFrom()}.
|
||||
* <p>
|
||||
* For example, if the website {@code http://example.com} redirects to {@code https://example.com}:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* If the website {@code https://google.com} has no redirects:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
Request redirectedFrom();
|
||||
/**
|
||||
* New request issued by the browser if the server responded with redirect.
|
||||
* <p>
|
||||
* This method is the opposite of {@code request.redirectedFrom()}:
|
||||
* This method is the opposite of [{@code method: Request.redirectedFrom}]:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
Request redirectedTo();
|
||||
/**
|
||||
* Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the following: {@code document}, {@code stylesheet}, {@code image}, {@code media}, {@code font}, {@code script}, {@code texttrack}, {@code xhr}, {@code fetch}, {@code eventsource}, {@code websocket}, {@code manifest}, {@code other}.
|
||||
* Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the
|
||||
* <p>
|
||||
* following: {@code document}, {@code stylesheet}, {@code image}, {@code media}, {@code font}, {@code script}, {@code texttrack}, {@code xhr}, {@code fetch}, {@code eventsource},
|
||||
* <p>
|
||||
* {@code websocket}, {@code manifest}, {@code other}.
|
||||
*/
|
||||
String resourceType();
|
||||
/**
|
||||
* Returns the matching Response object, or {@code null} if the response was not received due to error.
|
||||
* Returns the matching {@code Response} object, or {@code null} if the response was not received due to error.
|
||||
*/
|
||||
Response response();
|
||||
/**
|
||||
* Returns resource timing information for given request. Most of the timing values become available upon the response, {@code responseEnd} becomes available when request finishes. Find more information at Resource Timing API.
|
||||
* Returns resource timing information for given request. Most of the timing values become available upon the response,
|
||||
* <p>
|
||||
* {@code responseEnd} becomes available when request finishes. Find more information at
|
||||
* <p>
|
||||
* [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
RequestTiming timing();
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Response class represents responses which are received by page.
|
||||
* {@code Response} class represents responses which are received by page.
|
||||
*/
|
||||
public interface Response {
|
||||
/**
|
||||
@@ -31,7 +31,7 @@ public interface Response {
|
||||
*/
|
||||
String finished();
|
||||
/**
|
||||
* Returns the Frame that initiated this response.
|
||||
* Returns the {@code Frame} that initiated this response.
|
||||
*/
|
||||
Frame frame();
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ public interface Response {
|
||||
*/
|
||||
boolean ok();
|
||||
/**
|
||||
* Returns the matching Request object.
|
||||
* Returns the matching {@code Request} object.
|
||||
*/
|
||||
Request request();
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,9 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Whenever a network route is set up with {@code page.route(url, handler)} or {@code browserContext.route(url, handler)}, the {@code Route} object allows to handle the route.
|
||||
* Whenever a network route is set up with [{@code method: Page.route}] or [{@code method: BrowserContext.route}], the {@code Route} object
|
||||
* <p>
|
||||
* allows to handle the route.
|
||||
*/
|
||||
public interface Route {
|
||||
class ContinueOverrides {
|
||||
@@ -82,7 +84,8 @@ public interface Route {
|
||||
public String body;
|
||||
public byte[] bodyBytes;
|
||||
/**
|
||||
* Optional file path to respond with. The content type will be inferred from file extension. If {@code path} is a relative path, then it is resolved relative to the current working directory.
|
||||
* Optional file path to respond with. The content type will be inferred from file extension. If {@code path} is a relative path,
|
||||
* then it is resolved relative to the current working directory.
|
||||
*/
|
||||
public Path path;
|
||||
|
||||
@@ -117,20 +120,22 @@ public interface Route {
|
||||
/**
|
||||
* Aborts the route's request.
|
||||
* @param errorCode Optional error code. Defaults to {@code failed}, could be one of the following:
|
||||
* - {@code 'aborted'} - An operation was aborted (due to user action)
|
||||
* - {@code 'accessdenied'} - Permission to access a resource, other than the network, was denied
|
||||
* - {@code 'addressunreachable'} - The IP address is unreachable. This usually means that there is no route to the specified host or network.
|
||||
* - {@code 'blockedbyclient'} - The client chose to block the request.
|
||||
* - {@code 'blockedbyresponse'} - The request failed because the response was delivered along with requirements which are not met ('X-Frame-Options' and 'Content-Security-Policy' ancestor checks, for instance).
|
||||
* - {@code 'connectionaborted'} - A connection timed out as a result of not receiving an ACK for data sent.
|
||||
* - {@code 'connectionclosed'} - A connection was closed (corresponding to a TCP FIN).
|
||||
* - {@code 'connectionfailed'} - A connection attempt failed.
|
||||
* - {@code 'connectionrefused'} - A connection attempt was refused.
|
||||
* - {@code 'connectionreset'} - A connection was reset (corresponding to a TCP RST).
|
||||
* - {@code 'internetdisconnected'} - The Internet connection has been lost.
|
||||
* - {@code 'namenotresolved'} - The host name could not be resolved.
|
||||
* - {@code 'timedout'} - An operation timed out.
|
||||
* - {@code 'failed'} - A generic failure occurred.
|
||||
* - {@code 'aborted'} - An operation was aborted (due to user action)
|
||||
* - {@code 'accessdenied'} - Permission to access a resource, other than the network, was denied
|
||||
* - {@code 'addressunreachable'} - The IP address is unreachable. This usually means that there is no route to the specified
|
||||
* host or network.
|
||||
* - {@code 'blockedbyclient'} - The client chose to block the request.
|
||||
* - {@code 'blockedbyresponse'} - The request failed because the response was delivered along with requirements which are not
|
||||
* met ('X-Frame-Options' and 'Content-Security-Policy' ancestor checks, for instance).
|
||||
* - {@code 'connectionaborted'} - A connection timed out as a result of not receiving an ACK for data sent.
|
||||
* - {@code 'connectionclosed'} - A connection was closed (corresponding to a TCP FIN).
|
||||
* - {@code 'connectionfailed'} - A connection attempt failed.
|
||||
* - {@code 'connectionrefused'} - A connection attempt was refused.
|
||||
* - {@code 'connectionreset'} - A connection was reset (corresponding to a TCP RST).
|
||||
* - {@code 'internetdisconnected'} - The Internet connection has been lost.
|
||||
* - {@code 'namenotresolved'} - The host name could not be resolved.
|
||||
* - {@code 'timedout'} - An operation timed out.
|
||||
* - {@code 'failed'} - A generic failure occurred.
|
||||
*/
|
||||
void abort(String errorCode);
|
||||
default void continue_() {
|
||||
@@ -140,11 +145,19 @@ public interface Route {
|
||||
* Continues route's request with optional overrides.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* @param overrides Optional request overrides, can override following properties:
|
||||
*/
|
||||
void continue_(ContinueOverrides overrides);
|
||||
/**
|
||||
* Fulfills route's request with given response.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* @param response Response that will fulfill this route's request.
|
||||
*/
|
||||
void fulfill(FulfillResponse response);
|
||||
|
||||
@@ -20,12 +20,16 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Selectors can be used to install custom selector engines. See Working with selectors for more information.
|
||||
* Selectors can be used to install custom selector engines. See
|
||||
* <p>
|
||||
* [Working with selectors](./selectors.md#working-with-selectors) for more information.
|
||||
*/
|
||||
public interface Selectors {
|
||||
class RegisterOptions {
|
||||
/**
|
||||
* Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but not any JavaScript objects from the frame's scripts. Defaults to {@code false}. Note that running as a content script is not guaranteed when this engine is used together with other registered engines.
|
||||
* Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but
|
||||
* not any JavaScript objects from the frame's scripts. Defaults to {@code false}. Note that running as a content script is not
|
||||
* guaranteed when this engine is used together with other registered engines.
|
||||
*/
|
||||
public Boolean contentScript;
|
||||
|
||||
@@ -41,7 +45,10 @@ public interface Selectors {
|
||||
* An example of registering selector engine that queries elements based on a tag name:
|
||||
* <p>
|
||||
*
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May only contain {@code [a-zA-Z0-9_]} characters.
|
||||
* <p>
|
||||
*
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May only
|
||||
* contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param script Script that evaluates to a selector engine instance.
|
||||
*/
|
||||
void register(String name, Path path, RegisterOptions options);
|
||||
|
||||
@@ -19,7 +19,11 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. {@code page.waitForSelector(selector[, options])} or {@code browserType.launch([options])}.
|
||||
* - extends: [Error]
|
||||
* <p>
|
||||
* TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. [{@code method: Page.waitForSelector}]
|
||||
* <p>
|
||||
* or [{@code method: BrowserType.launch}].
|
||||
*/
|
||||
public interface TimeoutError {
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the touchscreen can only be used in browser contexts that have been intialized with {@code hasTouch} set to true.
|
||||
* The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the
|
||||
* <p>
|
||||
* touchscreen can only be used in browser contexts that have been intialized with {@code hasTouch} set to true.
|
||||
*/
|
||||
public interface Touchscreen {
|
||||
/**
|
||||
|
||||
@@ -22,10 +22,14 @@ import java.util.*;
|
||||
/**
|
||||
* When browser context is created with the {@code videosPath} option, each page has a video object associated with it.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface Video {
|
||||
/**
|
||||
* Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem upon closing the browser context.
|
||||
* Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem
|
||||
* <p>
|
||||
* upon closing the browser context.
|
||||
*/
|
||||
Path path();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* The WebSocket class represents websocket connections in the page.
|
||||
* The {@code WebSocket} class represents websocket connections in the page.
|
||||
*/
|
||||
public interface WebSocket {
|
||||
interface FrameData {
|
||||
@@ -69,7 +69,9 @@ public interface WebSocket {
|
||||
/**
|
||||
* Returns the event data value.
|
||||
* <p>
|
||||
* Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the webSocket is closed before the event is fired.
|
||||
* Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
||||
* <p>
|
||||
* value. Will throw an error if the webSocket is closed before the event is fired.
|
||||
* @param event Event name, same one would pass into {@code webSocket.on(event)}.
|
||||
*/
|
||||
Deferred<Event<EventType>> futureEvent(EventType event, FutureEventOptions options);
|
||||
|
||||
@@ -19,7 +19,13 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The Worker class represents a WebWorker. {@code worker} event is emitted on the page object to signal a worker creation. {@code close} event is emitted on the worker object when the worker is gone.
|
||||
* The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). {@code worker}
|
||||
* <p>
|
||||
* event is emitted on the page object to signal a worker creation. {@code close} event is emitted on the worker object when the
|
||||
* <p>
|
||||
* worker is gone.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
*/
|
||||
public interface Worker {
|
||||
@@ -35,9 +41,15 @@ public interface Worker {
|
||||
/**
|
||||
* Returns the return value of {@code pageFunction}
|
||||
* <p>
|
||||
* If the function passed to the {@code worker.evaluate} returns a Promise, then {@code worker.evaluate} would wait for the promise to resolve and return its value.
|
||||
* If the function passed to the {@code worker.evaluate} returns a [Promise], then {@code worker.evaluate} would wait for the promise
|
||||
* <p>
|
||||
* If the function passed to the {@code worker.evaluate} returns a non-Serializable value, then {@code worker.evaluate} returns {@code undefined}. DevTools Protocol also supports transferring some additional values that are not serializable by {@code JSON}: {@code -0}, {@code NaN}, {@code Infinity}, {@code -Infinity}, and bigint literals.
|
||||
* to resolve and return its value.
|
||||
* <p>
|
||||
* If the function passed to the {@code worker.evaluate} returns a non-[Serializable] value, then {@code worker.evaluate} returns
|
||||
* <p>
|
||||
* {@code undefined}. DevTools Protocol also supports transferring some additional values that are not serializable by {@code JSON}:
|
||||
* <p>
|
||||
* {@code -0}, {@code NaN}, {@code Infinity}, {@code -Infinity}, and bigint literals.
|
||||
* @param pageFunction Function to be evaluated in the worker context
|
||||
* @param arg Optional argument to pass to {@code pageFunction}
|
||||
*/
|
||||
@@ -48,9 +60,13 @@ public interface Worker {
|
||||
/**
|
||||
* Returns the return value of {@code pageFunction} as in-page object (JSHandle).
|
||||
* <p>
|
||||
* The only difference between {@code worker.evaluate} and {@code worker.evaluateHandle} is that {@code worker.evaluateHandle} returns in-page object (JSHandle).
|
||||
* The only difference between {@code worker.evaluate} and {@code worker.evaluateHandle} is that {@code worker.evaluateHandle} returns
|
||||
* <p>
|
||||
* If the function passed to the {@code worker.evaluateHandle} returns a Promise, then {@code worker.evaluateHandle} would wait for the promise to resolve and return its value.
|
||||
* in-page object (JSHandle).
|
||||
* <p>
|
||||
* If the function passed to the {@code worker.evaluateHandle} returns a [Promise], then {@code worker.evaluateHandle} would wait for
|
||||
* <p>
|
||||
* the promise to resolve and return its value.
|
||||
* @param pageFunction Function to be evaluated in the page context
|
||||
* @param arg Optional argument to pass to {@code pageFunction}
|
||||
*/
|
||||
|
||||
@@ -38,7 +38,7 @@ class DeviceDescriptorImpl implements DeviceDescriptor {
|
||||
}
|
||||
private ViewportImpl viewport;
|
||||
private String userAgent;
|
||||
private int deviceScaleFactor;
|
||||
private double deviceScaleFactor;
|
||||
private boolean isMobile;
|
||||
private boolean hasTouch;
|
||||
private String defaultBrowserType;
|
||||
@@ -54,7 +54,7 @@ class DeviceDescriptorImpl implements DeviceDescriptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deviceScaleFactor() {
|
||||
public double deviceScaleFactor() {
|
||||
return deviceScaleFactor;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldRespectDeviceScaleFactor() {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().withDeviceScaleFactor(3));
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().withDeviceScaleFactor(3.0));
|
||||
Page page = context.newPage();
|
||||
assertEquals(3, page.evaluate("window.devicePixelRatio"));
|
||||
context.close();
|
||||
@@ -128,7 +128,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
@Disabled("TODO: supported null viewport option")
|
||||
void shouldNotAllowDeviceScaleFactorWithNullViewport() {
|
||||
try {
|
||||
browser.newContext(new Browser.NewContextOptions().withDeviceScaleFactor(1));
|
||||
browser.newContext(new Browser.NewContextOptions().withDeviceScaleFactor(1.0));
|
||||
fail("did not throw");
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("\"deviceScaleFactor\" option is not supported with null \"viewport\""));
|
||||
|
||||
@@ -344,7 +344,7 @@ public class TestClick extends TestBase {
|
||||
void shouldClickTheButtonWithDeviceScaleFactorSet() {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.withViewport(400, 400)
|
||||
.withDeviceScaleFactor(5));
|
||||
.withDeviceScaleFactor(5.0));
|
||||
Page page = context.newPage();
|
||||
assertEquals(5, page.evaluate("() => window.devicePixelRatio"));
|
||||
page.setContent("<div style='width:100px;height:100px'>spacer</div>");
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0.180.0-next.1608746109749-cbc13bd
|
||||
1.8.0-next-1610046700000
|
||||
|
||||
@@ -21,7 +21,7 @@ if [[ ($1 == '-h') || ($1 == '--help') ]]; then
|
||||
fi
|
||||
|
||||
CLI_VERSION=$(head -1 ./CLI_VERSION)
|
||||
FILE_PREFIX=playwright-cli-$CLI_VERSION
|
||||
FILE_PREFIX=playwright-$CLI_VERSION
|
||||
|
||||
cd ../driver-bundle/src/main/resources
|
||||
|
||||
@@ -44,7 +44,7 @@ do
|
||||
cd $PLATFORM
|
||||
echo "Downloading driver for $PLATFORM to $(pwd)"
|
||||
|
||||
URL=https://playwright.azureedge.net/builds/cli
|
||||
URL=https://playwright.azureedge.net/builds/driver
|
||||
if ! [[ $CLI_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
URL=$URL/next
|
||||
fi
|
||||
|
||||
@@ -6,7 +6,7 @@ set +x
|
||||
trap "cd $(pwd -P)" EXIT
|
||||
cd "$(dirname $0)/.."
|
||||
|
||||
PLAYWRIGHT_CLI=./driver-bundle/src/main/resources/driver/linux/playwright-cli
|
||||
PLAYWRIGHT_CLI=./driver-bundle/src/main/resources/driver/linux/playwright.sh
|
||||
echo "Updating api.json from $($PLAYWRIGHT_CLI --version)"
|
||||
|
||||
$PLAYWRIGHT_CLI print-api-json > ./tools/api-generator/src/main/resources/api.json
|
||||
|
||||
+197
-60
@@ -17,6 +17,7 @@
|
||||
package com.microsoft.playwright.tools;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
@@ -107,35 +108,101 @@ class TypeRef extends Element {
|
||||
createCustomType();
|
||||
}
|
||||
|
||||
enum GeneratedType { ENUM, CLASS, OTHER };
|
||||
private static GeneratedType generatedTypeFor(JsonObject jsonType) {
|
||||
switch (jsonType.get("name").getAsString()) {
|
||||
case "union": {
|
||||
for (JsonElement item : jsonType.getAsJsonArray("union")) {
|
||||
String valueName = item.getAsJsonObject().get("name").getAsString();
|
||||
if ("null".equals(valueName)) {
|
||||
continue;
|
||||
}
|
||||
if (valueName.startsWith("\"")) {
|
||||
continue;
|
||||
}
|
||||
if (valueName.equals("Object")) {
|
||||
return GeneratedType.CLASS;
|
||||
}
|
||||
// If a value is not null and not a string it is a class name.
|
||||
return GeneratedType.OTHER;
|
||||
}
|
||||
return GeneratedType.ENUM;
|
||||
}
|
||||
case "Object": {
|
||||
return GeneratedType.CLASS;
|
||||
}
|
||||
case "Array":
|
||||
case "Promise": {
|
||||
for (JsonElement item : jsonType.getAsJsonArray("templates")) {
|
||||
return generatedTypeFor(item.getAsJsonObject());
|
||||
}
|
||||
return GeneratedType.OTHER;
|
||||
}
|
||||
default:
|
||||
return GeneratedType.OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
private static String typeExpression(JsonObject jsonType) {
|
||||
String typeName = jsonType.get("name").getAsString();
|
||||
if ("union".equals(typeName)) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (JsonElement item : jsonType.getAsJsonArray("union")) {
|
||||
values.add(typeExpression(item.getAsJsonObject()));
|
||||
}
|
||||
values.sort(String::compareTo);
|
||||
return String.join("|", values);
|
||||
}
|
||||
if ("function".equals(typeName)) {
|
||||
if (!jsonType.has("args")) {
|
||||
return typeName;
|
||||
}
|
||||
List<String> args = new ArrayList<>();
|
||||
for (JsonElement item : jsonType.getAsJsonArray("args")) {
|
||||
args.add(typeExpression(item.getAsJsonObject()));
|
||||
}
|
||||
String returnType = "";
|
||||
if (jsonType.has("returnType") && jsonType.get("returnType").isJsonObject()) {
|
||||
returnType = ":" + typeExpression(jsonType.getAsJsonObject("returnType"));
|
||||
}
|
||||
return typeName + "(" + String.join(", ", args) + ")" + returnType;
|
||||
}
|
||||
List<String> templateArgs = new ArrayList<>();
|
||||
if (jsonType.has("templates")) {
|
||||
for (JsonElement item : jsonType.getAsJsonArray("templates")) {
|
||||
templateArgs.add(typeExpression(item.getAsJsonObject()));
|
||||
}
|
||||
}
|
||||
if (templateArgs.isEmpty()) {
|
||||
return typeName;
|
||||
}
|
||||
return typeName + "<" + String.join(", ", templateArgs) + ">";
|
||||
}
|
||||
|
||||
void createCustomType() {
|
||||
boolean isEnum = jsonName.contains("|\"");
|
||||
boolean isClass = jsonName.replace("null|", "").equals("Object")
|
||||
|| jsonName.equals("Promise<Array<Object>>");
|
||||
GeneratedType generatedType = generatedTypeFor(jsonElement.getAsJsonObject());
|
||||
// Use path to the corresponding method, param of field as the key.
|
||||
String parentPath = parent.jsonPath;
|
||||
if (jsonName.equals("Array<Object>") && "BrowserContext.addCookies.cookies".equals(jsonPath)) {
|
||||
isClass = true;
|
||||
}
|
||||
if (jsonName.equals("Promise<Object>") && "BrowserContext.storageState".equals(jsonPath)) {
|
||||
isClass = true;
|
||||
}
|
||||
Types.Mapping mapping = TypeDefinition.types.findForPath(parentPath);
|
||||
if (mapping == null) {
|
||||
if (isEnum) {
|
||||
if (generatedType == GeneratedType.ENUM) {
|
||||
throw new RuntimeException("Cannot create enum, type mapping is missing for: " + parentPath);
|
||||
}
|
||||
if (!isClass) {
|
||||
if (generatedType != GeneratedType.CLASS) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent instanceof Field) {
|
||||
customType = toTitle(parent.jsonName);
|
||||
} else {
|
||||
// String typeExpression = typeExpression(jsonElement.getAsJsonObject());
|
||||
// System.out.println("add(\"" + parentPath + "\", \"" + typeExpression + "\", \"" + typeExpression + "\");" );
|
||||
customType = toTitle(parent.parent.jsonName) + toTitle(parent.jsonName);
|
||||
}
|
||||
} else {
|
||||
if (!mapping.from.equals(jsonName)) {
|
||||
throw new RuntimeException("Unexpected source type for: " + parentPath +". Expected: " + mapping.from + "; found: " + jsonName);
|
||||
String typeExpression = typeExpression(jsonElement.getAsJsonObject());
|
||||
if (!mapping.from.equals(typeExpression)) {
|
||||
throw new RuntimeException("Unexpected source type for: " + parentPath +". Expected: " + mapping.from + "; found: " + typeExpression);
|
||||
}
|
||||
customType = mapping.to;
|
||||
if (mapping.customMapping != null) {
|
||||
@@ -143,9 +210,9 @@ class TypeRef extends Element {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (isEnum) {
|
||||
typeScope().createEnum(customType, jsonName);
|
||||
} else if (isClass) {
|
||||
if (generatedType == GeneratedType.ENUM) {
|
||||
typeScope().createEnum(customType, jsonElement.getAsJsonObject());
|
||||
} else if (generatedType == GeneratedType.CLASS) {
|
||||
typeScope().createNestedClass(customType, this, jsonElement.getAsJsonObject());
|
||||
isNestedClass = true;
|
||||
}
|
||||
@@ -160,9 +227,12 @@ class TypeRef extends Element {
|
||||
}
|
||||
// Convert optional fields to boxed types.
|
||||
if (!parent.jsonElement.getAsJsonObject().get("required").getAsBoolean()) {
|
||||
if (jsonName.equals("number")) {
|
||||
if (jsonName.equals("int")) {
|
||||
return "Integer";
|
||||
}
|
||||
if (jsonName.equals("float")) {
|
||||
return "Double";
|
||||
}
|
||||
if (jsonName.equals("boolean")) {
|
||||
return "Boolean";
|
||||
}
|
||||
@@ -170,26 +240,51 @@ class TypeRef extends Element {
|
||||
if (jsonName.replace("null|", "").contains("|")) {
|
||||
throw new RuntimeException("Missing mapping for type union: " + jsonPath + ": " + jsonName);
|
||||
}
|
||||
return convertBuiltinType(stripPromise(jsonName));
|
||||
// System.out.println(jsonPath + " : " + jsonName);
|
||||
// if (jsonName.equals("Promise")) {
|
||||
// System.out.println(jsonElement);
|
||||
// }
|
||||
return convertBuiltinType(jsonElement.getAsJsonObject());
|
||||
}
|
||||
|
||||
private static String stripPromise(String type) {
|
||||
if ("Promise".equals(type)) {
|
||||
private static String convertBuiltinType(JsonObject jsonType) {
|
||||
String name = jsonType.get("name").getAsString();
|
||||
if ("int".equals(name)) {
|
||||
return "int";
|
||||
}
|
||||
if ("float".equals(name)) {
|
||||
return "double";
|
||||
}
|
||||
if ("string".equals(name)) {
|
||||
return "String";
|
||||
}
|
||||
if ("void".equals(name)) {
|
||||
return "void";
|
||||
}
|
||||
// Java API is sync just strip Promise<>
|
||||
if (type.startsWith("Promise<")) {
|
||||
return type.substring("Promise<".length(), type.length() - 1);
|
||||
if ("Array".equals(name)) {
|
||||
return "List<" + convertTemplateParams(jsonType) + ">";
|
||||
}
|
||||
return type;
|
||||
if ("Map".equals(name)) {
|
||||
return "Map<" + convertTemplateParams(jsonType) + ">";
|
||||
}
|
||||
if ("Promise".equals(name)) {
|
||||
return convertTemplateParams(jsonType);
|
||||
}
|
||||
if ("function".equals(name)) {
|
||||
throw new RuntimeException("Missing mapping for " + jsonType);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
private static String convertBuiltinType(String type) {
|
||||
return type.replace("Array<", "List<")
|
||||
.replace("Object<", "Map<")
|
||||
.replace("string", "String")
|
||||
.replace("number", "int")
|
||||
.replace("null|", "");
|
||||
private static String convertTemplateParams(JsonObject jsonType) {
|
||||
if (!jsonType.has("templates")) {
|
||||
return "";
|
||||
}
|
||||
List<String> params = new ArrayList<>();
|
||||
for (JsonElement item : jsonType.getAsJsonArray("templates")) {
|
||||
params.add(convertBuiltinType(item.getAsJsonObject()));
|
||||
}
|
||||
return String.join(", ", params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,8 +307,8 @@ abstract class TypeDefinition extends Element {
|
||||
return this;
|
||||
}
|
||||
|
||||
void createEnum(String name, String values) {
|
||||
addEnum(new Enum(this, name, values));
|
||||
void createEnum(String name, JsonObject jsonObject) {
|
||||
addEnum(new Enum(this, name, jsonObject));
|
||||
}
|
||||
|
||||
void addEnum(Enum newEnum) {
|
||||
@@ -458,9 +553,9 @@ class Method extends Element {
|
||||
returnType = null;
|
||||
} else {
|
||||
returnType = new TypeRef(this, jsonElement.get("type"));
|
||||
if (jsonElement.get("args") != null) {
|
||||
for (Map.Entry<String, JsonElement> arg : jsonElement.get("args").getAsJsonObject().entrySet()) {
|
||||
params.add(new Param(this, arg.getValue().getAsJsonObject()));
|
||||
if (jsonElement.has("args")) {
|
||||
for (JsonElement arg : jsonElement.getAsJsonArray("args")) {
|
||||
params.add(new Param(this, arg.getAsJsonObject()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -781,20 +876,31 @@ class Interface extends TypeDefinition {
|
||||
|
||||
Interface(JsonObject jsonElement) {
|
||||
super(null, jsonElement);
|
||||
for (Map.Entry<String, JsonElement> m : jsonElement.get("methods").getAsJsonObject().entrySet()) {
|
||||
methods.add(new Method(this, m.getValue().getAsJsonObject()));
|
||||
}
|
||||
for (Map.Entry<String, JsonElement> m : jsonElement.get("properties").getAsJsonObject().entrySet()) {
|
||||
// All properties are converted to methods in Java.
|
||||
methods.add(new Method(this, m.getValue().getAsJsonObject()));
|
||||
}
|
||||
for (Map.Entry<String, JsonElement> m : jsonElement.get("events").getAsJsonObject().entrySet()) {
|
||||
events.add(new Event(this, m.getValue().getAsJsonObject()));
|
||||
for (JsonElement item : jsonElement.getAsJsonArray("members")) {
|
||||
JsonObject memberJson = item.getAsJsonObject();
|
||||
switch (memberJson.get("kind").getAsString()) {
|
||||
case "method":
|
||||
// All properties are converted to methods in Java.
|
||||
case "property":
|
||||
if ("Playwright".equals(jsonName) && "errors".equals(memberJson.get("name").getAsString())) {
|
||||
continue;
|
||||
}
|
||||
methods.add(new Method(this, memberJson));
|
||||
break;
|
||||
case "event":
|
||||
events.add(new Event(this, memberJson));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected member kind: " + memberJson.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeTo(List<String> output, String offset) {
|
||||
output.add(header);
|
||||
if ("Playwright".equals(jsonName)) {
|
||||
output.add("import com.microsoft.playwright.impl.PlaywrightImpl;");
|
||||
}
|
||||
if (jsonName.equals("Route")) {
|
||||
output.add("import java.nio.charset.StandardCharsets;");
|
||||
}
|
||||
@@ -836,6 +942,14 @@ class Interface extends TypeDefinition {
|
||||
if ("Worker".equals(jsonName)) {
|
||||
output.add(offset + "Deferred<Event<EventType>> futureEvent(EventType event);");
|
||||
}
|
||||
if ("Playwright".equals(jsonName)) {
|
||||
output.add("");
|
||||
output.add(offset + "static Playwright create() {");
|
||||
output.add(offset + " return PlaywrightImpl.create();");
|
||||
output.add(offset + "}");
|
||||
output.add("");
|
||||
output.add(offset + "void close() throws Exception;");
|
||||
}
|
||||
output.add("}");
|
||||
output.add("\n");
|
||||
}
|
||||
@@ -1089,17 +1203,37 @@ class NestedClass extends TypeDefinition {
|
||||
deprecatedOptions.add("BrowserType.launch.options.logger");
|
||||
}
|
||||
|
||||
|
||||
NestedClass(Element parent, String name, JsonObject jsonElement) {
|
||||
super(parent, true, jsonElement);
|
||||
this.name = name;
|
||||
|
||||
if (jsonElement.has("properties")) {
|
||||
JsonObject properties = jsonElement.get("properties").getAsJsonObject();
|
||||
for (Map.Entry<String, JsonElement> m : properties.entrySet()) {
|
||||
if (deprecatedOptions.contains(jsonPath + "." + m.getKey())) {
|
||||
JsonObject jsonType = jsonElement;
|
||||
if ("union".equals(jsonName)) {
|
||||
for (JsonElement item : jsonType.getAsJsonArray("union")) {
|
||||
if (!"null".equals(item.getAsJsonObject().get("name").getAsString())) {
|
||||
jsonType = item.getAsJsonObject();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (jsonType.has("templates")) {
|
||||
JsonArray params = jsonType.getAsJsonArray("templates");
|
||||
if (params.size() != 1) {
|
||||
throw new RuntimeException("Unexpected number of parameters: " + jsonElement);
|
||||
}
|
||||
jsonType = params.get(0).getAsJsonObject();
|
||||
}
|
||||
|
||||
if (jsonType.has("properties")) {
|
||||
for (JsonElement item : jsonType.getAsJsonArray("properties")) {
|
||||
JsonObject propertyJson = item.getAsJsonObject();
|
||||
String propertyName = propertyJson.get("name").getAsString();
|
||||
if (deprecatedOptions.contains(jsonPath + "." + propertyName)) {
|
||||
continue;
|
||||
}
|
||||
fields.add(new Field(this, m.getKey(), m.getValue().getAsJsonObject()));
|
||||
fields.add(new Field(this, propertyName, propertyJson));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1176,14 +1310,17 @@ class Enum extends TypeDefinition {
|
||||
final String name;
|
||||
final List<String> enumValues;
|
||||
|
||||
Enum(TypeDefinition parent, String name, String values) {
|
||||
super(parent, null);
|
||||
Enum(TypeDefinition parent, String name, JsonObject jsonObject) {
|
||||
super(parent, jsonObject);
|
||||
this.name = name;
|
||||
String[] split = values.split("\\|");
|
||||
enumValues = Arrays.stream(split)
|
||||
.filter(s -> !"null".equals(s))
|
||||
.map(s -> s.substring(1, s.length() - 1).replace("-", "_").toUpperCase())
|
||||
.collect(Collectors.toList());
|
||||
enumValues = new ArrayList<>();
|
||||
for (JsonElement item : jsonObject.getAsJsonArray("union")) {
|
||||
String value = item.getAsJsonObject().get("name").getAsString();
|
||||
if ("null".equals(value)) {
|
||||
continue;
|
||||
}
|
||||
enumValues.add(value.substring(1, value.length() - 1).replace("-", "_").toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
void writeTo(List<String> output, String offset) {
|
||||
@@ -1205,17 +1342,17 @@ public class ApiGenerator {
|
||||
));
|
||||
|
||||
ApiGenerator(Reader reader) throws IOException {
|
||||
JsonObject api = new Gson().fromJson(reader, JsonObject.class);
|
||||
JsonArray api = new Gson().fromJson(reader, JsonArray.class);
|
||||
File cwd = FileSystems.getDefault().getPath(".").toFile();
|
||||
File dir = new File(cwd, "playwright/src/main/java/com/microsoft/playwright");
|
||||
System.out.println("Writing files to: " + dir.getCanonicalPath());
|
||||
for (Map.Entry<String, JsonElement> entry: api.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
for (JsonElement entry: api) {
|
||||
String name = entry.getAsJsonObject().get("name").getAsString();
|
||||
if (skipList.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
List<String> lines = new ArrayList<>();
|
||||
new Interface(entry.getValue().getAsJsonObject()).writeTo(lines, "");
|
||||
new Interface(entry.getAsJsonObject()).writeTo(lines, "");
|
||||
String text = String.join("\n", lines);
|
||||
try (FileWriter writer = new FileWriter(new File(dir, name + ".java"))) {
|
||||
writer.write(text);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* <p>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -60,8 +60,8 @@ class Types {
|
||||
add("Page.dblclick.options.button", "\"left\"|\"middle\"|\"right\"", "Mouse.Button", new Empty());
|
||||
add("Page.dblclick.options.modifiers", "Array<\"Alt\"|\"Control\"|\"Meta\"|\"Shift\">", "Set<Keyboard.Modifier>", new Empty());
|
||||
add("Page.tap.options.modifiers", "Array<\"Alt\"|\"Control\"|\"Meta\"|\"Shift\">", "Set<Keyboard.Modifier>", new Empty());
|
||||
add("Page.emulateMedia.params.media", "null|\"print\"|\"screen\"", "Media");
|
||||
add("Page.emulateMedia.params.colorScheme", "null|\"dark\"|\"light\"|\"no-preference\"", "ColorScheme", new Empty());
|
||||
add("Page.emulateMedia.params.media", "\"print\"|\"screen\"|null", "Media");
|
||||
add("Page.emulateMedia.params.colorScheme", "\"dark\"|\"light\"|\"no-preference\"|null", "ColorScheme", new Empty());
|
||||
add("Page.goBack.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "Frame.LoadState", new Empty());
|
||||
add("Page.goForward.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "Frame.LoadState", new Empty());
|
||||
add("Page.goto.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "Frame.LoadState", new Empty());
|
||||
@@ -69,7 +69,7 @@ class Types {
|
||||
add("Page.reload.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "Frame.LoadState", new Empty());
|
||||
add("Page.screenshot.options.type", "\"jpeg\"|\"png\"", "Type");
|
||||
add("Page.setContent.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "Frame.LoadState", new Empty());
|
||||
add("Page.waitForFunction.options.polling", "number|\"raf\"", "double", new PollingOption());
|
||||
add("Page.waitForFunction.options.polling", "\"raf\"|float", "double", new PollingOption());
|
||||
add("Page.waitForNavigation.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "Frame.LoadState", new Empty());
|
||||
add("Page.waitForSelector.options.state", "\"attached\"|\"detached\"|\"hidden\"|\"visible\"", "State");
|
||||
add("Frame.click.options.button", "\"left\"|\"middle\"|\"right\"", "Mouse.Button", new Empty());
|
||||
@@ -80,7 +80,7 @@ class Types {
|
||||
add("Frame.goto.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "LoadState", new Empty());
|
||||
add("Frame.hover.options.modifiers", "Array<\"Alt\"|\"Control\"|\"Meta\"|\"Shift\">", "Set<Keyboard.Modifier>", new Empty());
|
||||
add("Frame.setContent.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "LoadState", new Empty());
|
||||
add("Frame.waitForFunction.options.polling", "number|\"raf\"", "double", new PollingOption());
|
||||
add("Frame.waitForFunction.options.polling", "\"raf\"|float", "double", new PollingOption());
|
||||
add("Frame.waitForNavigation.options.waitUntil", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "LoadState", new Empty());
|
||||
add("Frame.waitForSelector.options.state", "\"attached\"|\"detached\"|\"hidden\"|\"visible\"", "State");
|
||||
add("ElementHandle.click.options.button", "\"left\"|\"middle\"|\"right\"", "Mouse.Button", new Empty());
|
||||
@@ -98,29 +98,29 @@ class Types {
|
||||
add("BrowserType.launchPersistentContext.options.colorScheme", "\"dark\"|\"light\"|\"no-preference\"", "ColorScheme", new Empty());
|
||||
|
||||
// File
|
||||
add("Page.addScriptTag.params.path", "string", "Path");
|
||||
add("Page.addStyleTag.params.path", "string", "Path");
|
||||
add("Page.pdf.options.path", "string", "Path");
|
||||
add("Page.screenshot.options.path", "string", "Path");
|
||||
add("Frame.addScriptTag.params.path", "string", "Path");
|
||||
add("Frame.addStyleTag.params.path", "string", "Path");
|
||||
add("ElementHandle.screenshot.options.path", "string", "Path");
|
||||
add("Route.fulfill.response.path", "string", "Path");
|
||||
add("Route.fulfill.response.status", "number", "int");
|
||||
add("Browser.newContext.options.recordHar.path", "string", "Path");
|
||||
add("Browser.newContext.options.recordVideo.dir", "string", "Path");
|
||||
add("Browser.newPage.options.recordHar.path", "string", "Path");
|
||||
add("Browser.newPage.options.recordVideo.dir", "string", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.recordHar.path", "string", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.recordVideo.dir", "string", "Path");
|
||||
add("BrowserType.launchPersistentContext.userDataDir", "string", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.executablePath", "string", "Path");
|
||||
add("BrowserType.launchServer.options.executablePath", "string", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.downloadsPath", "string", "Path");
|
||||
add("BrowserType.launch.options.executablePath", "string", "Path");
|
||||
add("BrowserType.launch.options.downloadsPath", "string", "Path");
|
||||
add("BrowserContext.storageState.options.path", "string", "Path");
|
||||
add("ChromiumBrowser.startTracing.options.path", "string", "Path");
|
||||
add("Page.addScriptTag.params.path", "path", "Path");
|
||||
add("Page.addStyleTag.params.path", "path", "Path");
|
||||
add("Page.pdf.options.path", "path", "Path");
|
||||
add("Page.screenshot.options.path", "path", "Path");
|
||||
add("Frame.addScriptTag.params.path", "path", "Path");
|
||||
add("Frame.addStyleTag.params.path", "path", "Path");
|
||||
add("ElementHandle.screenshot.options.path", "path", "Path");
|
||||
add("Route.fulfill.response.path", "path", "Path");
|
||||
add("Route.fulfill.response.status", "int", "int");
|
||||
add("Browser.newContext.options.recordHar.path", "path", "Path");
|
||||
add("Browser.newContext.options.recordVideo.dir", "path", "Path");
|
||||
add("Browser.newPage.options.recordHar.path", "path", "Path");
|
||||
add("Browser.newPage.options.recordVideo.dir", "path", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.recordHar.path", "path", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.recordVideo.dir", "path", "Path");
|
||||
add("BrowserType.launchPersistentContext.userDataDir", "path", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.executablePath", "path", "Path");
|
||||
add("BrowserType.launchServer.options.executablePath", "path", "Path");
|
||||
add("BrowserType.launchPersistentContext.options.downloadsPath", "path", "Path");
|
||||
add("BrowserType.launch.options.executablePath", "path", "Path");
|
||||
add("BrowserType.launch.options.downloadsPath", "path", "Path");
|
||||
add("BrowserContext.storageState.options.path", "path", "Path");
|
||||
add("ChromiumBrowser.startTracing.options.path", "path", "Path");
|
||||
add("Video.path", "Promise<string>", "Path");
|
||||
|
||||
// Route
|
||||
@@ -130,11 +130,11 @@ class Types {
|
||||
add("Page.unroute.handler", "function(Route, Request)", "Consumer<Route>");
|
||||
|
||||
// Viewport size.
|
||||
add("Browser.newContext.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("Browser.newPage.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("Browser.newContext.options.viewport", "Object|null", "Page.Viewport", new Empty());
|
||||
add("Browser.newPage.options.viewport", "Object|null", "Page.Viewport", new Empty());
|
||||
add("Page.setViewportSize.viewportSize", "Object", "Viewport", new Empty());
|
||||
add("Page.viewportSize", "null|Object", "Viewport", new Empty());
|
||||
add("BrowserType.launchPersistentContext.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("Page.viewportSize", "Object|null", "Viewport", new Empty());
|
||||
add("BrowserType.launchPersistentContext.options.viewport", "Object|null", "Page.Viewport", new Empty());
|
||||
|
||||
// RecordVideo size.
|
||||
add("Browser.newContext.options.recordVideo.size", "Object", "VideoSize", new Empty());
|
||||
@@ -145,7 +145,7 @@ class Types {
|
||||
add("Browser.newContext.options.httpCredentials", "Object", "BrowserContext.HTTPCredentials", new Empty());
|
||||
add("Browser.newPage.options.httpCredentials", "Object", "BrowserContext.HTTPCredentials", new Empty());
|
||||
add("BrowserType.launchPersistentContext.options.httpCredentials", "Object", "BrowserContext.HTTPCredentials", new Empty());
|
||||
add("BrowserContext.setHTTPCredentials.httpCredentials", "null|Object", "do nothing", new Empty());
|
||||
add("BrowserContext.setHTTPCredentials.httpCredentials", "Object|null", "do nothing", new Empty());
|
||||
|
||||
// EvaluationArgument
|
||||
add("Page.$eval.arg", "EvaluationArgument", "Object");
|
||||
@@ -181,13 +181,13 @@ class Types {
|
||||
add("ElementHandle.evaluate.pageFunction", "function", "String");
|
||||
add("JSHandle.evaluate.pageFunction", "function", "String");
|
||||
|
||||
add("BrowserContext.exposeBinding.playwrightBinding", "function", "Page.Binding");
|
||||
add("BrowserContext.exposeFunction.playwrightFunction", "function", "Page.Function");
|
||||
add("Page.exposeBinding.playwrightBinding", "function", "Binding");
|
||||
add("Page.exposeFunction.playwrightFunction", "function", "Function");
|
||||
add("BrowserContext.exposeBinding.callback", "function", "Page.Binding");
|
||||
add("BrowserContext.exposeFunction.callback", "function", "Page.Function");
|
||||
add("Page.exposeBinding.callback", "function", "Binding");
|
||||
add("Page.exposeFunction.callback", "function", "Function");
|
||||
|
||||
add("BrowserContext.addInitScript.script", "function|string|Object", "String");
|
||||
add("Page.addInitScript.script", "function|string|Object", "String");
|
||||
add("BrowserContext.addInitScript.script", "Object|function|string", "String");
|
||||
add("Page.addInitScript.script", "Object|function|string", "String");
|
||||
add("Page.evaluate.pageFunction", "function|string", "String");
|
||||
add("Page.evaluateHandle.pageFunction", "function|string", "String");
|
||||
add("Page.waitForFunction.pageFunction", "function|string", "String");
|
||||
@@ -196,7 +196,7 @@ class Types {
|
||||
add("Frame.waitForFunction.pageFunction", "function|string", "String");
|
||||
add("ElementHandle.evaluateHandle.pageFunction", "function|string", "String");
|
||||
add("JSHandle.evaluateHandle.pageFunction", "function|string", "String");
|
||||
add("Selectors.register.script", "function|string|Object", "String");
|
||||
add("Selectors.register.script", "Object|function|string", "String");
|
||||
add("Worker.evaluate.pageFunction", "function|string", "String");
|
||||
add("Worker.evaluateHandle.pageFunction", "function|string", "String");
|
||||
add("WebSocket.waitForEvent.optionsOrPredicate", "Function|Object", "String");
|
||||
@@ -204,35 +204,35 @@ class Types {
|
||||
// Return structures
|
||||
add("Dialog.type", "string", "Type", new Empty());
|
||||
add("ConsoleMessage.location", "Object", "Location");
|
||||
add("ElementHandle.boundingBox", "Promise<null|Object>", "BoundingBox", new Empty());
|
||||
add("Accessibility.snapshot", "Promise<null|Object>", "AccessibilityNode", new Empty());
|
||||
add("ElementHandle.boundingBox", "Promise<Object|null>", "BoundingBox", new Empty());
|
||||
add("Accessibility.snapshot", "Promise<Object|null>", "AccessibilityNode", new Empty());
|
||||
add("WebSocket.framereceived", "Object", "FrameData", new Empty());
|
||||
add("WebSocket.framesent", "Object", "FrameData", new Empty());
|
||||
|
||||
add("Page.waitForRequest", "Promise<Request>", "Deferred<Request>");
|
||||
add("Page.waitForResponse", "Promise<Response>", "Deferred<Response>");
|
||||
add("Page.waitForNavigation", "Promise<null|Response>", "Deferred<Response>");
|
||||
add("Frame.waitForNavigation", "Promise<null|Response>", "Deferred<Response>");
|
||||
add("Page.waitForSelector", "Promise<null|ElementHandle>", "ElementHandle", new Empty());
|
||||
add("Frame.waitForSelector", "Promise<null|ElementHandle>", "ElementHandle", new Empty());
|
||||
add("ElementHandle.waitForSelector", "Promise<null|ElementHandle>", "ElementHandle", new Empty());
|
||||
add("Page.waitForNavigation", "Promise<Response|null>", "Deferred<Response>");
|
||||
add("Frame.waitForNavigation", "Promise<Response|null>", "Deferred<Response>");
|
||||
add("Page.waitForSelector", "Promise<ElementHandle|null>", "ElementHandle", new Empty());
|
||||
add("Frame.waitForSelector", "Promise<ElementHandle|null>", "ElementHandle", new Empty());
|
||||
add("ElementHandle.waitForSelector", "Promise<ElementHandle|null>", "ElementHandle", new Empty());
|
||||
|
||||
add("Frame.waitForLoadState", "Promise", "void", new Empty());
|
||||
add("Page.waitForLoadState", "Promise", "void", new Empty());
|
||||
add("Frame.waitForTimeout", "Promise", "void", new Empty());
|
||||
add("Page.waitForTimeout", "Promise", "void", new Empty());
|
||||
add("Frame.waitForLoadState", "Promise<void>", "void", new Empty());
|
||||
add("Page.waitForLoadState", "Promise<void>", "void", new Empty());
|
||||
add("Frame.waitForTimeout", "Promise<void>", "void", new Empty());
|
||||
add("Page.waitForTimeout", "Promise<void>", "void", new Empty());
|
||||
add("Frame.waitForFunction", "Promise<JSHandle>", "JSHandle", new Empty());
|
||||
add("Page.waitForFunction", "Promise<JSHandle>", "JSHandle", new Empty());
|
||||
add("ElementHandle.waitForElementState", "Promise", "void", new Empty());
|
||||
add("ElementHandle.waitForElementState", "Promise<void>", "void", new Empty());
|
||||
|
||||
// Custom options
|
||||
add("Page.pdf.options.margin.top", "string|number", "String");
|
||||
add("Page.pdf.options.margin.right", "string|number", "String");
|
||||
add("Page.pdf.options.margin.bottom", "string|number", "String");
|
||||
add("Page.pdf.options.margin.left", "string|number", "String");
|
||||
add("Page.pdf.options.width", "string|number", "String");
|
||||
add("Page.pdf.options.height", "string|number", "String");
|
||||
add("Page.pdf.options.scale", "number", "Double");
|
||||
add("Page.pdf.options.margin.top", "float|string", "String");
|
||||
add("Page.pdf.options.margin.right", "float|string", "String");
|
||||
add("Page.pdf.options.margin.bottom", "float|string", "String");
|
||||
add("Page.pdf.options.margin.left", "float|string", "String");
|
||||
add("Page.pdf.options.width", "float|string", "String");
|
||||
add("Page.pdf.options.height", "float|string", "String");
|
||||
add("Page.pdf.options.scale", "float", "Double");
|
||||
|
||||
add("Page.goto.options", "Object", "NavigateOptions");
|
||||
add("Frame.goto.options", "Object", "NavigateOptions");
|
||||
@@ -250,47 +250,47 @@ class Types {
|
||||
// The method has custom signatures
|
||||
add("BrowserContext.cookies", "Promise<Array<Object>>", "Cookie");
|
||||
add("BrowserContext.cookies.sameSite", "\"Lax\"|\"None\"|\"Strict\"", "SameSite", new Empty());
|
||||
add("BrowserContext.cookies.expires", "number", "long");
|
||||
add("BrowserContext.cookies.expires", "float", "long");
|
||||
add("BrowserContext.addCookies.cookies", "Array<Object>", "AddCookie");
|
||||
add("BrowserContext.addCookies.cookies.sameSite", "\"Lax\"|\"None\"|\"Strict\"", "SameSite", new Empty());
|
||||
add("BrowserContext.addCookies.cookies.expires", "number", "Long", new Empty());
|
||||
add("BrowserContext.route.url", "string|RegExp|function(URL):boolean", "String");
|
||||
add("BrowserContext.unroute.url", "string|RegExp|function(URL):boolean", "String");
|
||||
add("BrowserContext.addCookies.cookies.expires", "float", "Long", new Empty());
|
||||
add("BrowserContext.route.url", "RegExp|function(URL):boolean|string", "String");
|
||||
add("BrowserContext.unroute.url", "RegExp|function(URL):boolean|string", "String");
|
||||
add("BrowserContext.storageState", "Promise<Object>", "StorageState", new Empty());
|
||||
add("BrowserContext.waitForEvent.event", "string", "EventType", new Empty());
|
||||
add("BrowserContext.waitForEvent.optionsOrPredicate", "Function|Object", "String");
|
||||
add("BrowserContext.waitForEvent", "Promise<Object>", "Deferred<Event<EventType>>", new Empty());
|
||||
add("Page.waitForNavigation.options.url", "string|RegExp|Function", "Custom");
|
||||
add("BrowserContext.waitForEvent", "Promise<any>", "Deferred<Event<EventType>>", new Empty());
|
||||
add("Page.waitForNavigation.options.url", "RegExp|function(URL):boolean|string", "Custom");
|
||||
add("Page.waitForNavigation.options", "Object", "FutureNavigationOptions");
|
||||
add("Page.waitForRequest.options", "Object", "FutureRequestOptions");
|
||||
add("Page.waitForResponse.options", "Object", "FutureResponseOptions");
|
||||
add("Page.frame.options", "string|Object", "FrameOptions", new Empty());
|
||||
add("Page.route.url", "string|RegExp|function(URL):boolean", "String");
|
||||
add("Page.selectOption.values", "null|string|ElementHandle|Array<string>|Object|Array<ElementHandle>|Array<Object>", "String");
|
||||
add("Page.setInputFiles.files", "string|Array<string>|Object|Array<Object>", "String");
|
||||
add("Page.unroute.url", "string|RegExp|function(URL):boolean", "String");
|
||||
add("Page.route.url", "RegExp|function(URL):boolean|string", "String");
|
||||
add("Page.selectOption.values", "Array<ElementHandle>|Array<Object>|Array<string>|ElementHandle|Object|null|string", "String");
|
||||
add("Page.setInputFiles.files", "Array<Object>|Array<path>|Object|path", "String");
|
||||
add("Page.unroute.url", "RegExp|function(URL):boolean|string", "String");
|
||||
add("Page.waitForEvent.event", "string", "EventType", new Empty());
|
||||
add("Page.waitForEvent.optionsOrPredicate", "Function|Object", "WaitForEventOptions");
|
||||
add("Page.waitForEvent", "Promise<Object>", "Deferred<Event<EventType>>", new Empty());
|
||||
add("Page.waitForRequest.urlOrPredicate", "string|RegExp|Function", "String");
|
||||
add("Page.waitForResponse.urlOrPredicate", "string|RegExp|function(Response):boolean", "String");
|
||||
add("Frame.waitForNavigation.options.url", "string|RegExp|Function", "Custom");
|
||||
add("Page.waitForEvent", "Promise<any>", "Deferred<Event<EventType>>", new Empty());
|
||||
add("Page.waitForRequest.urlOrPredicate", "RegExp|function(Request):boolean|string", "String");
|
||||
add("Page.waitForResponse.urlOrPredicate", "RegExp|function(Response):boolean|string", "String");
|
||||
add("Frame.waitForNavigation.options.url", "RegExp|function(URL):boolean|string", "Custom");
|
||||
add("Frame.waitForNavigation.options", "Object", "FutureNavigationOptions");
|
||||
add("Frame.selectOption.values", "null|string|ElementHandle|Array<string>|Object|Array<ElementHandle>|Array<Object>", "String");
|
||||
add("Frame.setInputFiles.files", "string|Array<string>|Object|Array<Object>", "String");
|
||||
add("ElementHandle.selectOption.values", "null|string|ElementHandle|Array<string>|Object|Array<ElementHandle>|Array<Object>", "String");
|
||||
add("ElementHandle.setInputFiles.files", "string|Array<string>|Object|Array<Object>", "String");
|
||||
add("FileChooser.setFiles.files", "string|Array<string>|Object|Array<Object>", "String");
|
||||
add("Route.continue.overrides.postData", "string|Buffer", "byte[]");
|
||||
add("Route.fulfill.response.body", "string|Buffer", "String");
|
||||
add("BrowserType.launch.options.ignoreDefaultArgs", "boolean|Array<string>", "Custom");
|
||||
add("BrowserType.launch.options.firefoxUserPrefs", "Object<string, string|number|boolean>", "String");
|
||||
add("BrowserType.launch.options.env", "Object<string, string|number|boolean>", "Map<String, String>");
|
||||
add("BrowserType.launchPersistentContext.options.ignoreDefaultArgs", "boolean|Array<string>", "Custom");
|
||||
add("BrowserType.launchPersistentContext.options.env", "Object<string, string|number|boolean>", "Map<String, String>");
|
||||
add("BrowserType.launchServer.options.ignoreDefaultArgs", "boolean|Array<string>", "Custom");
|
||||
add("BrowserType.launchServer.options.firefoxUserPrefs", "Object<string, string|number|boolean>", "String");
|
||||
add("BrowserType.launchServer.options.env", "Object<string, string|number|boolean>", "Map<String, String>");
|
||||
add("Frame.selectOption.values", "Array<ElementHandle>|Array<Object>|Array<string>|ElementHandle|Object|null|string", "String");
|
||||
add("Frame.setInputFiles.files", "Array<Object>|Array<path>|Object|path", "String");
|
||||
add("ElementHandle.selectOption.values", "Array<ElementHandle>|Array<Object>|Array<string>|ElementHandle|Object|null|string", "String");
|
||||
add("ElementHandle.setInputFiles.files", "Array<Object>|Array<path>|Object|path", "String");
|
||||
add("FileChooser.setFiles.files", "Array<Object>|Array<path>|Object|path", "String");
|
||||
add("Route.continue.overrides.postData", "Buffer|string", "byte[]", new Empty());
|
||||
add("Route.fulfill.response.body", "Buffer|string", "String");
|
||||
add("BrowserType.launch.options.ignoreDefaultArgs", "Array<string>|boolean", "Custom");
|
||||
add("BrowserType.launch.options.firefoxUserPrefs", "Object<string, boolean|float|string>", "Map<String, Object>", new Empty());
|
||||
add("BrowserType.launch.options.env", "Object<string, boolean|float|string>", "Map<String, String>", new Empty());
|
||||
add("BrowserType.launchPersistentContext.options.ignoreDefaultArgs", "Array<string>|boolean", "Custom");
|
||||
add("BrowserType.launchPersistentContext.options.env", "Object<string, boolean|float|string>", "Map<String, String>", new Empty());
|
||||
add("BrowserType.launchServer.options.ignoreDefaultArgs", "Array<string>|boolean", "Custom");
|
||||
add("BrowserType.launchServer.options.firefoxUserPrefs", "Object<string, boolean|float|string>", "Map<String, Object>", new Empty());
|
||||
add("BrowserType.launchServer.options.env", "Object<string, boolean|float|string>", "Map<String, String>", new Empty());
|
||||
add("Logger.log.message", "string|Error", "String");
|
||||
|
||||
add("Browser.newContext.options.geolocation.latitude", "number", "double");
|
||||
@@ -303,15 +303,15 @@ class Types {
|
||||
add("BrowserType.launchPersistentContext.options.geolocation.longitude", "number", "double");
|
||||
add("BrowserType.launchPersistentContext.options.geolocation.accuracy", "number", "double");
|
||||
|
||||
add("BrowserContext.setGeolocation.geolocation", "null|Object", "Geolocation", new Empty());
|
||||
add("BrowserContext.setGeolocation.geolocation", "Object|null", "Geolocation", new Empty());
|
||||
add("Browser.newContext.options.geolocation", "Object", "Geolocation", new Empty());
|
||||
add("Browser.newContext.options.storageState", "string|Object", "BrowserContext.StorageState", new Empty());
|
||||
add("Browser.newPage.options.storageState", "string|Object", "BrowserContext.StorageState", new Empty());
|
||||
add("Browser.newContext.options.storageState", "Object|path", "BrowserContext.StorageState", new Empty());
|
||||
add("Browser.newPage.options.storageState", "Object|path", "BrowserContext.StorageState", new Empty());
|
||||
add("Browser.newPage.options.geolocation", "Object", "Geolocation", new Empty());
|
||||
add("BrowserType.launchPersistentContext.options.geolocation", "Object", "Geolocation", new Empty());
|
||||
add("Download.saveAs.path", "string", "Path", new Empty());
|
||||
add("Download.saveAs.path", "path", "Path", new Empty());
|
||||
add("Download.path", "Promise<null|string>", "Path", new Empty());
|
||||
add("Download.createReadStream", "Promise<null|Readable>", "InputStream", new Empty());
|
||||
add("Download.createReadStream", "Promise<Readable|null>", "InputStream", new Empty());
|
||||
|
||||
// Single field options
|
||||
add("Keyboard.type.options", "Object", "int", new Empty());
|
||||
@@ -320,16 +320,84 @@ class Types {
|
||||
// node.js types
|
||||
add("BrowserServer.process", "ChildProcess", "Object");
|
||||
|
||||
add("Page.pdf", "Promise<Buffer>", "byte[]");
|
||||
add("Page.screenshot", "Promise<Buffer>", "byte[]");
|
||||
add("ElementHandle.screenshot", "Promise<Buffer>", "byte[]");
|
||||
add("Request.postDataBuffer", "null|Buffer", "byte[]");
|
||||
add("Response.body", "Promise<Buffer>", "byte[]");
|
||||
add("Response.finished", "Promise<null|Error>", "String");
|
||||
add("ChromiumBrowser.stopTracing", "Promise<Buffer>", "byte[]");
|
||||
add("WebSocket.framereceived.payload", "string|Buffer", "byte[]");
|
||||
add("WebSocket.framesent.payload", "string|Buffer", "byte[]");
|
||||
add("Page.pdf", "Promise<Buffer>", "byte[]", new Empty());
|
||||
add("Page.screenshot", "Promise<Buffer>", "byte[]", new Empty());
|
||||
add("ElementHandle.screenshot", "Promise<Buffer>", "byte[]", new Empty());
|
||||
add("Request.postDataBuffer", "Buffer|null", "byte[]", new Empty());
|
||||
add("Response.body", "Promise<Buffer>", "byte[]", new Empty());
|
||||
add("Response.finished", "Promise<Error|null>", "String");
|
||||
add("ChromiumBrowser.stopTracing", "Promise<Buffer>", "byte[]", new Empty());
|
||||
add("WebSocket.framereceived.payload", "Buffer|string", "byte[]", new Empty());
|
||||
add("WebSocket.framesent.payload", "Buffer|string", "byte[]", new Empty());
|
||||
|
||||
add("BrowserContext.browser", "Browser|null", "Browser");
|
||||
add("BrowserContext.cookies.urls", "Array<string>|string", "Custom", new Empty());
|
||||
add("Page.$", "Promise<ElementHandle|null>", "ElementHandle");
|
||||
add("Page.frame", "Frame|null", "Frame");
|
||||
add("Page.frame.frameSelector", "Object|string", "Custom", new Empty());
|
||||
add("Page.getAttribute", "Promise<null|string>", "String", new Empty());
|
||||
add("Page.goBack", "Promise<Response|null>", "Response", new Empty());
|
||||
add("Page.goForward", "Promise<Response|null>", "Response", new Empty());
|
||||
add("Page.goto", "Promise<Response|null>", "Response", new Empty());
|
||||
add("Page.opener", "Promise<Page|null>", "Page", new Empty());
|
||||
add("Page.reload", "Promise<Response|null>", "Response", new Empty());
|
||||
add("Page.textContent", "Promise<null|string>", "String", new Empty());
|
||||
add("Page.video", "Video|null", "Video", new Empty());
|
||||
add("Frame.$", "Promise<ElementHandle|null>", "ElementHandle", new Empty());
|
||||
add("Frame.getAttribute", "Promise<null|string>", "String", new Empty());
|
||||
add("Frame.goto", "Promise<Response|null>", "Response", new Empty());
|
||||
add("Frame.parentFrame", "Frame|null", "Frame", new Empty());
|
||||
add("Frame.textContent", "Promise<null|string>", "String", new Empty());
|
||||
add("ElementHandle.$", "Promise<ElementHandle|null>", "ElementHandle", new Empty());
|
||||
add("ElementHandle.contentFrame", "Promise<Frame|null>", "Frame", new Empty());
|
||||
add("ElementHandle.getAttribute", "Promise<null|string>", "String", new Empty());
|
||||
add("ElementHandle.ownerFrame", "Promise<Frame|null>", "Frame", new Empty());
|
||||
add("ElementHandle.textContent", "Promise<null|string>", "String", new Empty());
|
||||
add("JSHandle.asElement", "ElementHandle|null", "ElementHandle", new Empty());
|
||||
add("Download.failure", "Promise<null|string>", "String", new Empty());
|
||||
// add("Request.failure", "Object|null", "Object", new Empty());
|
||||
add("Request.postData", "null|string", "String", new Empty());
|
||||
add("Request.redirectedFrom", "Request|null", "Request", new Empty());
|
||||
add("Request.redirectedTo", "Request|null", "Request", new Empty());
|
||||
add("Request.response", "Promise<Response|null>", "Response", new Empty());
|
||||
|
||||
// TODO: fix upstream types!
|
||||
add("Request.headers", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("Response.headers", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("Browser.newContext.options.extraHTTPHeaders", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("Browser.newPage.options.extraHTTPHeaders", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("BrowserType.launchPersistentContext.options.extraHTTPHeaders", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("Page.setExtraHTTPHeaders.headers", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("BrowserContext.setExtraHTTPHeaders.headers", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("Route.continue.overrides.headers", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
add("Route.fulfill.response.headers", "Object<string, string>", "Map<String, String>", new Empty());
|
||||
|
||||
add("BrowserContext.setDefaultTimeout.timeout", "float", "int", new Empty());
|
||||
add("BrowserContext.setDefaultNavigationTimeout.timeout", "float", "int", new Empty());
|
||||
add("Page.waitForRequest.options.timeout", "float", "Integer", new Empty());
|
||||
add("Page.waitForResponse.options.timeout", "float", "Integer", new Empty());
|
||||
add("Page.waitForTimeout.timeout", "float", "int", new Empty());
|
||||
add("Frame.waitForTimeout.timeout", "float", "int", new Empty());
|
||||
add("Page.goto.options.timeout", "float", "Integer", new Empty());
|
||||
add("Frame.goto.options.timeout", "float", "Integer", new Empty());
|
||||
add("Page.setDefaultTimeout.timeout", "float", "int", new Empty());
|
||||
add("Page.setDefaultNavigationTimeout.timeout", "float", "int", new Empty());
|
||||
add("Frame.waitForLoadState.options.timeout", "float", "Integer", new Empty());
|
||||
add("Page.waitForLoadState.options.timeout", "float", "Integer", new Empty());
|
||||
add("Frame.waitForNavigation.options.timeout", "float", "Integer", new Empty());
|
||||
add("Page.waitForNavigation.options.timeout", "float", "Integer", new Empty());
|
||||
add("ElementHandle.waitForElementState.options.timeout", "float", "Integer", new Empty());
|
||||
add("Page.waitForFunction.options.timeout", "float", "Integer", new Empty());
|
||||
add("Mouse.click.x", "float", "int", new Empty());
|
||||
add("Mouse.click.y", "float", "int", new Empty());
|
||||
add("Mouse.dblclick.x", "float", "int", new Empty());
|
||||
add("Mouse.dblclick.y", "float", "int", new Empty());
|
||||
add("Mouse.move.x", "float", "int", new Empty());
|
||||
add("Mouse.move.y", "float", "int", new Empty());
|
||||
add("Touchscreen.tap.x", "float", "int", new Empty());
|
||||
add("Touchscreen.tap.y", "float", "int", new Empty());
|
||||
|
||||
add("Playwright.devices", "Object", "Map<String, DeviceDescriptor>", new Empty());
|
||||
|
||||
// JSON type
|
||||
add("BrowserContext.addInitScript.arg", "Serializable", "Object");
|
||||
|
||||
Reference in New Issue
Block a user