chore: simplify credentials and viewport api
This commit is contained in:
@@ -128,9 +128,6 @@ class TypeRef extends Element {
|
||||
if (jsonName.replace("null|", "").contains("|")) {
|
||||
throw new RuntimeException("Missing mapping for type union: " + jsonPath + ": " + jsonName);
|
||||
}
|
||||
// if (jsonPath.contains("geolocation")) {
|
||||
// System.out.println(jsonPath + ": " + jsonName);
|
||||
// }
|
||||
return convertBuiltinType(stripPromise(jsonName));
|
||||
}
|
||||
|
||||
@@ -299,6 +296,13 @@ class Method extends Element {
|
||||
tsToJavaMethodName.put("goto", "navigate");
|
||||
}
|
||||
|
||||
private static Map<String, String> customSignature = new HashMap<>();
|
||||
static {
|
||||
customSignature.put("Page.setViewportSize", "void setViewportSize(int width, int height);");
|
||||
customSignature.put("BrowserContext.setHTTPCredentials", "void setHTTPCredentials(String username, String password);");
|
||||
customSignature.put("ChromiumBrowserContext.setHTTPCredentials", "void setHTTPCredentials(String username, String password);");
|
||||
}
|
||||
|
||||
Method(TypeDefinition parent, JsonObject jsonElement) {
|
||||
super(parent, jsonElement);
|
||||
returnType = new TypeRef(this, jsonElement.get("type"));
|
||||
@@ -322,6 +326,10 @@ class Method extends Element {
|
||||
}
|
||||
|
||||
void writeTo(List<String> output, String offset) {
|
||||
if (customSignature.containsKey(jsonPath)) {
|
||||
output.add(offset + customSignature.get(jsonPath));
|
||||
return;
|
||||
}
|
||||
for (int i = params.size() - 1; i >= 0; i--) {
|
||||
Param p = params.get(i);
|
||||
if (!p.isOptional()) {
|
||||
@@ -411,10 +419,20 @@ class Field extends Element {
|
||||
}
|
||||
|
||||
void writeBuilderMethod(List<String> output, String offset, String parentClass) {
|
||||
if (type.isNestedClass) {
|
||||
if (name.equals("httpCredentials") && type.toJava().equals("HttpCredentials")) {
|
||||
output.add(offset + "public " + parentClass + " with" + toTitle(name) + "(String username, String password) {");
|
||||
output.add(offset + " this." + name + " = new " + type.toJava() + "();");
|
||||
output.add(offset + " this." + name + ".username = username;");
|
||||
output.add(offset + " this." + name + ".password = password;");
|
||||
output.add(offset + " return this;");
|
||||
} else if (type.isNestedClass) {
|
||||
output.add(offset + "public " + type.toJava() + " set" + toTitle(name) + "() {");
|
||||
output.add(offset + " this." + name + " = new " + type.toJava() + "();");
|
||||
output.add(offset + " return this." + name + ";");
|
||||
} else if ("Page.Viewport".equals(type.toJava()) || "Viewport".equals(type.toJava())) {
|
||||
output.add(offset + "public " + parentClass + " with" + toTitle(name) + "(int width, int height) {");
|
||||
output.add(offset + " this." + name + " = new " + type.toJava() + "(width, height);");
|
||||
output.add(offset + " return this;");
|
||||
} else if ("Set<Keyboard.Modifier>".equals(type.toJava())) {
|
||||
output.add(offset + "public " + parentClass + " with" + toTitle(name) + "(Keyboard.Modifier... modifiers) {");
|
||||
output.add(offset + " this." + name + " = new HashSet<>(Arrays.asList(modifiers));");
|
||||
@@ -498,6 +516,26 @@ class Interface extends TypeDefinition {
|
||||
output.add(offset + "enum Modifier { ALT, CONTROL, META, SHIFT }");
|
||||
break;
|
||||
}
|
||||
case "Page": {
|
||||
output.add(offset + "class Viewport {");
|
||||
output.add(offset + " private final int width;");
|
||||
output.add(offset + " private final int height;");
|
||||
output.add("");
|
||||
output.add(offset + " public Viewport(int width, int height) {");
|
||||
output.add(offset + " this.width = width;");
|
||||
output.add(offset + " this.height = height;");
|
||||
output.add(offset + " }");
|
||||
output.add("");
|
||||
output.add(offset + " public int width() {");
|
||||
output.add(offset + " return width;");
|
||||
output.add(offset + " }");
|
||||
output.add("");
|
||||
output.add(offset + " public int height() {");
|
||||
output.add(offset + " return height;");
|
||||
output.add(offset + " }");
|
||||
output.add(offset + "}");
|
||||
break;
|
||||
}
|
||||
default: return;
|
||||
}
|
||||
output.add("");
|
||||
|
||||
@@ -108,6 +108,30 @@ class Types {
|
||||
add("ChromiumBrowserContext.route.handler", "function(Route, Request)", "BiConsumer<Route, Request>");
|
||||
add("ChromiumBrowserContext.unroute.handler", "function(Route, Request)", "BiConsumer<Route, Request>");
|
||||
|
||||
// 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("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("ChromiumBrowser.newContext.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("ChromiumBrowser.newPage.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("FirefoxBrowser.newContext.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("FirefoxBrowser.newPage.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("WebKitBrowser.newContext.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
add("WebKitBrowser.newPage.options.viewport", "null|Object", "Page.Viewport", new Empty());
|
||||
|
||||
// HTTP credentials.
|
||||
add("Browser.newContext.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("Browser.newPage.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("BrowserType.launchPersistentContext.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("ChromiumBrowser.newContext.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("ChromiumBrowser.newPage.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("FirefoxBrowser.newContext.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("FirefoxBrowser.newPage.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("WebKitBrowser.newContext.options.httpCredentials", "Object", "HttpCredentials");
|
||||
add("WebKitBrowser.newPage.options.httpCredentials", "Object", "HttpCredentials");
|
||||
|
||||
// EvaluationArgument
|
||||
add("Page.$eval.arg", "EvaluationArgument", "Object");
|
||||
add("Page.$$eval.arg", "EvaluationArgument", "Object");
|
||||
@@ -245,7 +269,6 @@ class Types {
|
||||
add("ChromiumBrowserContext.setGeolocation.geolocation", "null|Object", "Geolocation");
|
||||
add("BrowserContext.setHTTPCredentials.httpCredentials", "null|Object", "HTTPCredentials");
|
||||
add("ChromiumBrowserContext.setHTTPCredentials.httpCredentials", "null|Object", "HTTPCredentials");
|
||||
add("Page.setViewportSize.viewportSize", "Object", "ViewportSize");
|
||||
|
||||
// Single field options
|
||||
add("Keyboard.type.options", "Object", "int", new Empty());
|
||||
@@ -288,6 +311,9 @@ class Types {
|
||||
}
|
||||
|
||||
private void add(String jsonPath, String fromType, String toType) {
|
||||
if (jsonPathToMapping.containsKey(jsonPath)) {
|
||||
throw new RuntimeException("Duplicate entry: " + jsonPath);
|
||||
}
|
||||
jsonPathToMapping.put(jsonPath, new Mapping(fromType, toType));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,25 +22,6 @@ import java.util.function.BiConsumer;
|
||||
public interface Browser {
|
||||
class NewContextOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -106,7 +87,7 @@ public interface Browser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -138,9 +119,9 @@ public interface Browser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -186,9 +167,11 @@ public interface Browser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewContextOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
@@ -217,25 +200,6 @@ public interface Browser {
|
||||
}
|
||||
class NewPageOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -301,7 +265,7 @@ public interface Browser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -333,9 +297,9 @@ public interface Browser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewPageOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -381,9 +345,11 @@ public interface Browser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewPageOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
|
||||
@@ -86,7 +86,7 @@ public interface BrowserContext {
|
||||
void setDefaultTimeout(int timeout);
|
||||
void setExtraHTTPHeaders(Map<String, String> headers);
|
||||
void setGeolocation(Geolocation geolocation);
|
||||
void setHTTPCredentials(HTTPCredentials httpCredentials);
|
||||
void setHTTPCredentials(String username, String password);
|
||||
void setOffline(boolean offline);
|
||||
default void unroute(String url) {
|
||||
unroute(url, null);
|
||||
|
||||
@@ -191,25 +191,6 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public LaunchPersistentContextOptions done() {
|
||||
return LaunchPersistentContextOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -291,7 +272,7 @@ public interface BrowserType {
|
||||
public Integer slowMo;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -386,9 +367,9 @@ public interface BrowserType {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public LaunchPersistentContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -434,9 +415,11 @@ public interface BrowserType {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public LaunchPersistentContextOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public LaunchPersistentContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
|
||||
@@ -40,25 +40,6 @@ public interface ChromiumBrowser {
|
||||
}
|
||||
class NewContextOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -124,7 +105,7 @@ public interface ChromiumBrowser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -156,9 +137,9 @@ public interface ChromiumBrowser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -204,9 +185,11 @@ public interface ChromiumBrowser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewContextOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
@@ -235,25 +218,6 @@ public interface ChromiumBrowser {
|
||||
}
|
||||
class NewPageOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -319,7 +283,7 @@ public interface ChromiumBrowser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -351,9 +315,9 @@ public interface ChromiumBrowser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewPageOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -399,9 +363,11 @@ public interface ChromiumBrowser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewPageOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
|
||||
@@ -88,7 +88,7 @@ public interface ChromiumBrowserContext {
|
||||
void setDefaultTimeout(int timeout);
|
||||
void setExtraHTTPHeaders(Map<String, String> headers);
|
||||
void setGeolocation(Geolocation geolocation);
|
||||
void setHTTPCredentials(HTTPCredentials httpCredentials);
|
||||
void setHTTPCredentials(String username, String password);
|
||||
void setOffline(boolean offline);
|
||||
default void unroute(String url) {
|
||||
unroute(url, null);
|
||||
|
||||
@@ -22,25 +22,6 @@ import java.util.function.BiConsumer;
|
||||
public interface FirefoxBrowser {
|
||||
class NewContextOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -106,7 +87,7 @@ public interface FirefoxBrowser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -138,9 +119,9 @@ public interface FirefoxBrowser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -186,9 +167,11 @@ public interface FirefoxBrowser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewContextOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
@@ -217,25 +200,6 @@ public interface FirefoxBrowser {
|
||||
}
|
||||
class NewPageOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -301,7 +265,7 @@ public interface FirefoxBrowser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -333,9 +297,9 @@ public interface FirefoxBrowser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewPageOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -381,9 +345,11 @@ public interface FirefoxBrowser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewPageOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
|
||||
@@ -20,6 +20,24 @@ import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public interface Page {
|
||||
class Viewport {
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
public Viewport(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int width() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int height() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
enum LoadState { DOMCONTENTLOADED, LOAD, NETWORKIDLE }
|
||||
class CloseOptions {
|
||||
public Boolean runBeforeUnload;
|
||||
@@ -601,19 +619,6 @@ public interface Page {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ViewportSize {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public ViewportSize withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public ViewportSize withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class TextContentOptions {
|
||||
public Integer timeout;
|
||||
|
||||
@@ -658,17 +663,6 @@ public interface Page {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class PageViewportSize {
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public int width() {
|
||||
return this.width;
|
||||
}
|
||||
public int height() {
|
||||
return this.height;
|
||||
}
|
||||
}
|
||||
class WaitForFunctionOptions {
|
||||
public double polling;
|
||||
public Integer timeout;
|
||||
@@ -872,7 +866,7 @@ public interface Page {
|
||||
setInputFiles(selector, files, null);
|
||||
}
|
||||
void setInputFiles(String selector, String files, SetInputFilesOptions options);
|
||||
void setViewportSize(ViewportSize viewportSize);
|
||||
void setViewportSize(int width, int height);
|
||||
default String textContent(String selector) {
|
||||
return textContent(selector, null);
|
||||
}
|
||||
@@ -891,7 +885,7 @@ public interface Page {
|
||||
}
|
||||
void unroute(String url, BiConsumer<Route, Request> handler);
|
||||
String url();
|
||||
PageViewportSize viewportSize();
|
||||
Viewport viewportSize();
|
||||
default Object waitForEvent(String event) {
|
||||
return waitForEvent(event, null);
|
||||
}
|
||||
|
||||
@@ -22,25 +22,6 @@ import java.util.function.BiConsumer;
|
||||
public interface WebKitBrowser {
|
||||
class NewContextOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewContextOptions done() {
|
||||
return NewContextOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -106,7 +87,7 @@ public interface WebKitBrowser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -138,9 +119,9 @@ public interface WebKitBrowser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewContextOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -186,9 +167,11 @@ public interface WebKitBrowser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewContextOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
@@ -217,25 +200,6 @@ public interface WebKitBrowser {
|
||||
}
|
||||
class NewPageOptions {
|
||||
public enum ColorScheme { DARK, LIGHT, NO_PREFERENCE }
|
||||
public class Viewport {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
Viewport() {
|
||||
}
|
||||
public NewPageOptions done() {
|
||||
return NewPageOptions.this;
|
||||
}
|
||||
|
||||
public Viewport withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
public Viewport withHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public class Geolocation {
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
@@ -301,7 +265,7 @@ public interface WebKitBrowser {
|
||||
public Boolean acceptDownloads;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public Boolean bypassCSP;
|
||||
public Viewport viewport;
|
||||
public Page.Viewport viewport;
|
||||
public String userAgent;
|
||||
public Integer deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
@@ -333,9 +297,9 @@ public interface WebKitBrowser {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
public Viewport setViewport() {
|
||||
this.viewport = new Viewport();
|
||||
return this.viewport;
|
||||
public NewPageOptions withViewport(int width, int height) {
|
||||
this.viewport = new Page.Viewport(width, height);
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
@@ -381,9 +345,11 @@ public interface WebKitBrowser {
|
||||
this.offline = offline;
|
||||
return this;
|
||||
}
|
||||
public HttpCredentials setHttpCredentials() {
|
||||
public NewPageOptions withHttpCredentials(String username, String password) {
|
||||
this.httpCredentials = new HttpCredentials();
|
||||
return this.httpCredentials;
|
||||
this.httpCredentials.username = username;
|
||||
this.httpCredentials.password = password;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Main {
|
||||
System.out.println("browser = " + browser);
|
||||
|
||||
Browser.NewContextOptions contextOptions = new Browser.NewContextOptions();
|
||||
contextOptions.setViewport().withWidth(800).withHeight(600);
|
||||
contextOptions.withViewport(800, 600);
|
||||
BrowserContext context = browser.newContext(contextOptions);
|
||||
Page page = context.newPage();
|
||||
// page.navigate("http://example.com", null);
|
||||
|
||||
@@ -142,7 +142,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHTTPCredentials(HTTPCredentials httpCredentials) {
|
||||
public void setHTTPCredentials(String username, String password) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -416,7 +416,6 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
@Override
|
||||
public String title() {
|
||||
JsonElement json = sendMessage("title", new JsonObject());
|
||||
System.out.println(new Gson().toJson(json));
|
||||
return json.getAsJsonObject().get("value").getAsString();
|
||||
}
|
||||
|
||||
|
||||
@@ -347,9 +347,12 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setViewportSize(ViewportSize viewportSize) {
|
||||
public void setViewportSize(int width, int height) {
|
||||
JsonObject size = new JsonObject();
|
||||
size.addProperty("width", width);
|
||||
size.addProperty("height", height);
|
||||
JsonObject params = new JsonObject();
|
||||
params.add("viewportSize", new Gson().toJsonTree(viewportSize).getAsJsonObject());
|
||||
params.add("viewportSize", size);
|
||||
sendMessage("setViewportSize", params);
|
||||
}
|
||||
|
||||
@@ -384,7 +387,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageViewportSize viewportSize() {
|
||||
public Viewport viewportSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -269,10 +269,7 @@ public class TestClick {
|
||||
// @see https://github.com/GoogleChrome/puppeteer/issues/161
|
||||
DeviceDescriptor descriptor = playwright.devices().get("iPhone 6");
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setViewport()
|
||||
.withWidth(descriptor.viewport().width())
|
||||
.withHeight(descriptor.viewport().height())
|
||||
.done()
|
||||
.withViewport(descriptor.viewport().width(), descriptor.viewport().height())
|
||||
.withHasTouch(descriptor.hasTouch()));
|
||||
Page page = context.newPage();
|
||||
page.mouse().down();
|
||||
@@ -413,10 +410,7 @@ public class TestClick {
|
||||
void should_click_the_button_with_offset_with_page_scale() {
|
||||
// TODO: test.skip(browserName === "firefox");
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setViewport()
|
||||
.withWidth(400)
|
||||
.withHeight(400)
|
||||
.done()
|
||||
.withViewport(400, 400)
|
||||
.withIsMobile(true));
|
||||
Page page = context.newPage();
|
||||
page.navigate(server.PREFIX + "/input/button.html");
|
||||
|
||||
@@ -138,7 +138,7 @@ public class TestPopup {
|
||||
void should_inherit_http_credentials_from_browser_context() {
|
||||
server.setAuth("/title.html", "user", "pass");
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setHttpCredentials().withUsername("user").withPassword("pass").done());
|
||||
.withHttpCredentials("user", "pass"));
|
||||
Page page = context.newPage();
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
Deferred<Page> popup = page.waitForPopup();
|
||||
@@ -151,7 +151,7 @@ public class TestPopup {
|
||||
@Test
|
||||
void should_inherit_touch_support_from_browser_context() {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setViewport().withWidth(400).withHeight(500).done()
|
||||
.withViewport(400, 500)
|
||||
.withHasTouch(true));
|
||||
Page page = context.newPage();
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
@@ -166,7 +166,7 @@ public class TestPopup {
|
||||
@Test
|
||||
void should_inherit_viewport_size_from_browser_context() {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setViewport().withWidth(400).withHeight(500).done());
|
||||
.withViewport(400, 500));
|
||||
Page page = context.newPage();
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
Object size = page.evaluate("() => {\n" +
|
||||
@@ -180,7 +180,7 @@ public class TestPopup {
|
||||
@Test
|
||||
void should_use_viewport_size_from_window_features() {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setViewport().withWidth(700).withHeight(700).done());
|
||||
.withViewport(700, 700));
|
||||
Page page = context.newPage();
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
Deferred<Page> popupEvent = page.waitForPopup();
|
||||
@@ -189,7 +189,7 @@ public class TestPopup {
|
||||
" return { width: win.innerWidth, height: win.innerHeight };\n" +
|
||||
"}");
|
||||
Page popup = popupEvent.get();
|
||||
popup.setViewportSize(new Page.ViewportSize().withWidth(500).withHeight(400));
|
||||
popup.setViewportSize(500, 400);
|
||||
popup.waitForLoadState();
|
||||
Object resized = popup.evaluate("() => ({ width: window.innerWidth, height: window.innerHeight })");
|
||||
context.close();
|
||||
|
||||
Reference in New Issue
Block a user