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 goback and goforward #2838

Merged
merged 2 commits into from
Dec 6, 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 @@ -285,21 +285,6 @@
"FAIL"
]
},
{
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
"testIdPattern": "[navigation.spec] navigation Page.goBack *",
"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] *timeout*",
Expand Down
27 changes: 25 additions & 2 deletions lib/PuppeteerSharp/Bidi/BidiPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PuppeteerSharp.Bidi.Core;
using PuppeteerSharp.Helpers;
Expand Down Expand Up @@ -105,10 +106,10 @@ internal BidiPage(BidiBrowserContext browserContext, BrowsingContext browsingCon
public override Task<FileChooser> WaitForFileChooserAsync(WaitForOptions options = null) => throw new NotImplementedException();

/// <inheritdoc />
public override Task<IResponse> GoBackAsync(NavigationOptions options = null) => throw new NotImplementedException();
public override Task<IResponse> GoBackAsync(NavigationOptions options = null) => GoAsync(-1, options);

/// <inheritdoc />
public override Task<IResponse> GoForwardAsync(NavigationOptions options = null) => throw new NotImplementedException();
public override Task<IResponse> GoForwardAsync(NavigationOptions options = null) => GoAsync(1, options);

/// <inheritdoc />
public override Task SetBurstModeOffAsync() => throw new NotImplementedException();
Expand Down Expand Up @@ -211,6 +212,28 @@ internal static BidiPage From(BidiBrowserContext browserContext, BrowsingContext
/// <inheritdoc />
protected override Task ExposeFunctionAsync(string name, Delegate puppeteerFunction) => throw new NotImplementedException();

private async Task<IResponse> GoAsync(int delta, NavigationOptions options)
{
var waitForNavigationTask = WaitForNavigationAsync(options);
var navigationTask = BidiMainFrame.BrowsingContext.TraverseHistoryAsync(delta);

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;
}

private void Initialize()
{
}
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 @@ -141,6 +141,9 @@ internal WindowRealm CreateWindowRealm(string sandbox = null)
return realm;
}

internal async Task TraverseHistoryAsync(int delta)
=> await Session.Driver.BrowsingContext.TraverseHistoryAsync(new TraverseHistoryCommandParameters(Id, delta)).ConfigureAwait(false);

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

private void Initialize()
Expand Down
Loading