From 5cd00cc4c7239fe3aa5cabcf63e10aea94855c7a Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 2 Apr 2021 14:10:43 -0700 Subject: [PATCH] chore: roll to 1.11.0-next-1617387566000 (#384) --- .../com/microsoft/playwright/BrowserType.java | 2 +- .../com/microsoft/playwright/Download.java | 2 +- .../com/microsoft/playwright/Playwright.java | 6 ++--- .../java/com/microsoft/playwright/Video.java | 3 +-- .../playwright/impl/BrowserContextImpl.java | 5 +++- .../microsoft/playwright/impl/PageImpl.java | 27 ++++++++++--------- scripts/CLI_VERSION | 2 +- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java index 5e76f52c..7d96ff09 100644 --- a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java +++ b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java @@ -70,7 +70,7 @@ public interface BrowserType { public List args; /** * Browser distribution channel. Read more about using Google Chrome and Microsoft Edge. + * href="https://playwright.dev/java/docs/browsers/#google-chrome--microsoft-edge">Google Chrome and Microsoft Edge. */ public BrowserChannel channel; /** diff --git a/playwright/src/main/java/com/microsoft/playwright/Download.java b/playwright/src/main/java/com/microsoft/playwright/Download.java index 8d173a79..a00307bc 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Download.java +++ b/playwright/src/main/java/com/microsoft/playwright/Download.java @@ -61,7 +61,7 @@ public interface Download { String failure(); /** * Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if - * necessary. The method throws when connected remotely via {@link BrowserType#connect BrowserType.connect()}. + * necessary. The method throws when connected remotely. */ Path path(); /** diff --git a/playwright/src/main/java/com/microsoft/playwright/Playwright.java b/playwright/src/main/java/com/microsoft/playwright/Playwright.java index a3166375..a6622c2a 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Playwright.java +++ b/playwright/src/main/java/com/microsoft/playwright/Playwright.java @@ -41,11 +41,11 @@ import java.util.*; */ public interface Playwright extends AutoCloseable { /** - * This object can be used to launch or connect to Chromium, returning instances of {@code ChromiumBrowser}. + * This object can be used to launch or connect to Chromium, returning instances of {@code Browser}. */ BrowserType chromium(); /** - * This object can be used to launch or connect to Firefox, returning instances of {@code FirefoxBrowser}. + * This object can be used to launch or connect to Firefox, returning instances of {@code Browser}. */ BrowserType firefox(); /** @@ -54,7 +54,7 @@ public interface Playwright extends AutoCloseable { */ Selectors selectors(); /** - * This object can be used to launch or connect to WebKit, returning instances of {@code WebKitBrowser}. + * This object can be used to launch or connect to WebKit, returning instances of {@code Browser}. */ BrowserType webkit(); /** diff --git a/playwright/src/main/java/com/microsoft/playwright/Video.java b/playwright/src/main/java/com/microsoft/playwright/Video.java index 5589adf4..bac79c49 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Video.java +++ b/playwright/src/main/java/com/microsoft/playwright/Video.java @@ -32,8 +32,7 @@ public interface Video { void delete(); /** * 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. This method throws when connected remotely via {@link BrowserType#connect - * BrowserType.connect()}. + * upon closing the browser context. This method throws when connected remotely. */ Path path(); /** diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java index a0b381e7..7132683d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java @@ -395,8 +395,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext { } } else if ("page".equals(event)) { PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString()); - listeners.notify(EventType.PAGE, page); pages.add(page); + listeners.notify(EventType.PAGE, page); + if (page.opener() != null && !page.opener().isClosed()) { + page.opener().notifyPopup(page); + } } else if ("bindingCall".equals(event)) { BindingCall bindingCall = connection.getExistingObject(params.getAsJsonObject("binding").get("guid").getAsString()); BindingCallback binding = bindings.get(bindingCall.name()); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java index 774d2cef..4e98da47 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java @@ -71,6 +71,7 @@ public class PageImpl extends ChannelOwner implements Page { final Set workers = new HashSet<>(); private final TimeoutSettings timeoutSettings; private VideoImpl video; + private final PageImpl opener; enum EventType { CLOSE, @@ -109,6 +110,11 @@ public class PageImpl extends ChannelOwner implements Page { frames.add(mainFrame); timeoutSettings = new TimeoutSettings(browserContext.timeoutSettings); waitableClosedOrCrashed = createWaitForCloseHelper(); + if (initializer.has("opener")) { + opener = connection.getExistingObject(initializer.getAsJsonObject("opener").get("guid").getAsString()); + } else { + opener = null; + } } @Override @@ -121,10 +127,6 @@ public class PageImpl extends ChannelOwner implements Page { } else { dialog.dismiss(); } - } else if ("popup".equals(event)) { - String guid = params.getAsJsonObject("page").get("guid").getAsString(); - PageImpl popup = connection.getExistingObject(guid); - listeners.notify(EventType.POPUP, popup); } else if ("worker".equals(event)) { String guid = params.getAsJsonObject("worker").get("guid").getAsString(); WorkerImpl worker = connection.getExistingObject(guid); @@ -235,6 +237,10 @@ public class PageImpl extends ChannelOwner implements Page { } } + void notifyPopup(PageImpl popup) { + listeners.notify(EventType.POPUP, popup); + } + void didClose() { isClosed = true; browserContext.pages.remove(this); @@ -849,14 +855,11 @@ public class PageImpl extends ChannelOwner implements Page { } @Override - public Page opener() { - return withLogging("Page.opener", () -> { - JsonObject result = sendMessage("opener").getAsJsonObject(); - if (!result.has("page")) { - return null; - } - return connection.getExistingObject(result.getAsJsonObject("page").get("guid").getAsString()); - }); + public PageImpl opener() { + if (opener == null || opener.isClosed()) { + return null; + } + return opener; } @Override diff --git a/scripts/CLI_VERSION b/scripts/CLI_VERSION index b3b3163a..82da482c 100644 --- a/scripts/CLI_VERSION +++ b/scripts/CLI_VERSION @@ -1 +1 @@ -1.11.0-next-1617218236000 +1.11.0-next-1617387566000