Skip to content

Commit

Permalink
Bidi: Page.ReloadAsync (#2854)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Dec 30, 2024
1 parent 6fc9019 commit fe03be5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,6 @@
"FAIL"
]
},
{
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
"testIdPattern": "[navigation.spec] navigation Page.reload*",
"platforms": [
"darwin",
"linux",
"win32"
],
"parameters": [
"webDriverBiDi"
],
"expectations": [
"FAIL"
]
},
{
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
"testIdPattern": "[navigation.spec] *should work when reload causes history API in beforeunload*",
Expand Down
4 changes: 0 additions & 4 deletions lib/PuppeteerSharp.Tests/NavigationTests/PageReloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ namespace PuppeteerSharp.Tests.NavigationTests
{
public class PageReloadTests : PuppeteerPageBaseTest
{
public PageReloadTests() : base()
{
}

[Test, Retry(2), PuppeteerTest("navigation.spec", "navigation Page.reload", "should work")]
public async Task ShouldWork()
{
Expand Down
22 changes: 21 additions & 1 deletion lib/PuppeteerSharp/Bidi/BidiPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,27 @@ public override async Task BringToFrontAsync()
public override Task EmulateCPUThrottlingAsync(decimal? factor = null) => throw new NotImplementedException();

/// <inheritdoc />
public override Task<IResponse> ReloadAsync(NavigationOptions options) => throw new NotImplementedException();
public override async Task<IResponse> ReloadAsync(NavigationOptions options)
{
var waitForNavigationTask = WaitForNavigationAsync(options);
var navigationTask = BidiMainFrame.BrowsingContext.ReloadAsync();

try
{
await Task.WhenAll(waitForNavigationTask, navigationTask).ConfigureAwait(false);
}
catch (Exception ex)
{
if (ex.Message.Contains("no such history entry"))
{
return null;
}

throw new NavigationException(ex.Message, ex);
}

return waitForNavigationTask.Result;
}

/// <inheritdoc />
public override Task<IRequest> WaitForRequestAsync(Func<IRequest, bool> predicate, WaitForOptions options = null) => throw new NotImplementedException();
Expand Down
3 changes: 3 additions & 0 deletions lib/PuppeteerSharp/Bidi/Core/BrowsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ internal WindowRealm CreateWindowRealm(string sandbox = null)
internal async Task TraverseHistoryAsync(int delta)
=> await Session.Driver.BrowsingContext.TraverseHistoryAsync(new TraverseHistoryCommandParameters(Id, delta)).ConfigureAwait(false);

internal async Task ReloadAsync()
=> await Session.Driver.BrowsingContext.ReloadAsync(new ReloadCommandParameters(Id)).ConfigureAwait(false);

protected virtual void OnBrowsingContextCreated(BidiBrowsingContextEventArgs e) => BrowsingContextCreated?.Invoke(this, e);

private void Initialize()
Expand Down

0 comments on commit fe03be5

Please sign in to comment.