Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bidi: Page.ReloadAsync #2854

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading