From d87d75c37d0be5f92010212c7a4fdae959199dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Mon, 22 Feb 2021 10:00:40 -0300 Subject: [PATCH] feat(page): introduce Page.PauseAsync (#1168) --- src/PlaywrightSharp/BrowserContext.cs | 2 ++ src/PlaywrightSharp/IPage.cs | 13 ++++++++++++- src/PlaywrightSharp/Page.cs | 3 +++ .../Transport/Channels/BrowserContextChannel.cs | 3 +++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/PlaywrightSharp/BrowserContext.cs b/src/PlaywrightSharp/BrowserContext.cs index 1c9e88cefb..eae3d24d33 100644 --- a/src/PlaywrightSharp/BrowserContext.cs +++ b/src/PlaywrightSharp/BrowserContext.cs @@ -331,6 +331,8 @@ public async Task GetStorageStateAsync(string path = null) return state; } + internal Task PauseAsync() => Channel.PauseAsync(); + internal void OnRoute(Route route, Request request) { foreach (var item in _routes) diff --git a/src/PlaywrightSharp/IPage.cs b/src/PlaywrightSharp/IPage.cs index cd5135f57b..04298833c1 100644 --- a/src/PlaywrightSharp/IPage.cs +++ b/src/PlaywrightSharp/IPage.cs @@ -29,7 +29,6 @@ using System.IO; using System.Text.Json; using System.Text.RegularExpressions; -using System.Threading; using System.Threading.Tasks; using PlaywrightSharp.Input; @@ -1803,5 +1802,17 @@ Task GetPdfAsync( /// The default value can be changed by using the or . /// A that completes when the message is processed by the browser. Task IsVisibleAsync(string selector, int? timeout = null); + + /// + /// Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume' button + /// in the page overlay or to call `playwright.resume()` in the DevTools console. + /// + /// User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from + /// the place it was paused. + /// + /// > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the . + /// + /// A that completes when the message is processed by the browser. + Task PauseAsync(); } } diff --git a/src/PlaywrightSharp/Page.cs b/src/PlaywrightSharp/Page.cs index 0c7e192e60..40aff6741e 100644 --- a/src/PlaywrightSharp/Page.cs +++ b/src/PlaywrightSharp/Page.cs @@ -948,6 +948,9 @@ public Task TapAsync(string selector, Modifier[] modifiers = null, Point? positi /// public Task IsVisibleAsync(string selector, int? timeout = null) => MainFrame.IsVisibleAsync(true, selector, timeout); + /// + public Task PauseAsync() => Context.PauseAsync(); + internal void OnFrameNavigated(Frame frame) => FrameNavigated?.Invoke(this, new FrameEventArgs(frame)); diff --git a/src/PlaywrightSharp/Transport/Channels/BrowserContextChannel.cs b/src/PlaywrightSharp/Transport/Channels/BrowserContextChannel.cs index cb6df66578..e4ac0c62d3 100644 --- a/src/PlaywrightSharp/Transport/Channels/BrowserContextChannel.cs +++ b/src/PlaywrightSharp/Transport/Channels/BrowserContextChannel.cs @@ -222,5 +222,8 @@ internal Task NewCDPSessionAsync(IPage page) internal Task GetStorageStateAsync() => Connection.SendMessageToServerAsync(Guid, "storageState", null); + + internal Task PauseAsync() + => Connection.SendMessageToServerAsync(Guid, "pause", null); } }