|
23 | 23 | using System; |
24 | 24 | using System.Collections.Concurrent; |
25 | 25 | using System.Collections.Generic; |
| 26 | +using System.Linq; |
26 | 27 | using System.Threading.Tasks; |
27 | 28 | using PuppeteerSharp.Bidi.Core; |
28 | 29 | using PuppeteerSharp.Helpers; |
@@ -105,10 +106,10 @@ internal BidiPage(BidiBrowserContext browserContext, BrowsingContext browsingCon |
105 | 106 | public override Task<FileChooser> WaitForFileChooserAsync(WaitForOptions options = null) => throw new NotImplementedException(); |
106 | 107 |
|
107 | 108 | /// <inheritdoc /> |
108 | | - public override Task<IResponse> GoBackAsync(NavigationOptions options = null) => throw new NotImplementedException(); |
| 109 | + public override Task<IResponse> GoBackAsync(NavigationOptions options = null) => GoAsync(-1, options); |
109 | 110 |
|
110 | 111 | /// <inheritdoc /> |
111 | | - public override Task<IResponse> GoForwardAsync(NavigationOptions options = null) => throw new NotImplementedException(); |
| 112 | + public override Task<IResponse> GoForwardAsync(NavigationOptions options = null) => GoAsync(1, options); |
112 | 113 |
|
113 | 114 | /// <inheritdoc /> |
114 | 115 | public override Task SetBurstModeOffAsync() => throw new NotImplementedException(); |
@@ -211,6 +212,28 @@ internal static BidiPage From(BidiBrowserContext browserContext, BrowsingContext |
211 | 212 | /// <inheritdoc /> |
212 | 213 | protected override Task ExposeFunctionAsync(string name, Delegate puppeteerFunction) => throw new NotImplementedException(); |
213 | 214 |
|
| 215 | + private async Task<IResponse> GoAsync(int delta, NavigationOptions options) |
| 216 | + { |
| 217 | + var waitForNavigationTask = WaitForNavigationAsync(options); |
| 218 | + var navigationTask = BidiMainFrame.BrowsingContext.TraverseHistoryAsync(delta); |
| 219 | + |
| 220 | + try |
| 221 | + { |
| 222 | + await Task.WhenAll(waitForNavigationTask, navigationTask).ConfigureAwait(false); |
| 223 | + } |
| 224 | + catch (Exception ex) |
| 225 | + { |
| 226 | + if (ex.Message.Contains("no such history entry")) |
| 227 | + { |
| 228 | + return null; |
| 229 | + } |
| 230 | + |
| 231 | + throw new NavigationException(ex.Message, ex); |
| 232 | + } |
| 233 | + |
| 234 | + return waitForNavigationTask.Result; |
| 235 | + } |
| 236 | + |
214 | 237 | private void Initialize() |
215 | 238 | { |
216 | 239 | } |
|
0 commit comments