Skip to content

Commit

Permalink
Bidi: Page goback and goforward
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Dec 5, 2024
1 parent 66f2267 commit 34b5dd8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,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

0 comments on commit 34b5dd8

Please sign in to comment.