Skip to content

Commit

Permalink
Improve SetContentAsync and LifecycleWatcher (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Jan 5, 2019
1 parent d61fe13 commit aff3de2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,13 @@ await EvaluateFunctionAsync(@"html => {
document.close();
}", html);

var watcher = new LifecycleWatcher(FrameManager, this, timeout, options);
var watcher = new LifecycleWatcher(FrameManager, this, waitUntil, timeout);

var watcherTask = await Task.WhenAny(
watcher.TimeoutOrTerminationTask,
watcher.LifecycleTask).ConfigureAwait(false);

await watcherTask;
await watcherTask.ConfigureAwait(false);
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions lib/PuppeteerSharp/FrameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public async Task<Response> NavigateFrameAsync(Frame frame, string url, Navigati
: options.Referer;
var requests = new Dictionary<string, Request>();
var timeout = options?.Timeout ?? DefaultNavigationTimeout;
using (var watcher = new LifecycleWatcher(this, frame, timeout, options))

using (var watcher = new LifecycleWatcher(this, frame, options?.WaitUntil, timeout))
{
try
{
Expand Down Expand Up @@ -121,7 +122,7 @@ private async Task NavigateAsync(CDPSession client, string url, string referrer,
public async Task<Response> WaitForFrameNavigationAsync(Frame frame, NavigationOptions options = null)
{
var timeout = options?.Timeout ?? DefaultNavigationTimeout;
using (var watcher = new LifecycleWatcher(this, frame, timeout, options))
using (var watcher = new LifecycleWatcher(this, frame, options?.WaitUntil, timeout))
{
var raceTask = await Task.WhenAny(
watcher.NewDocumentNavigationTask,
Expand Down
15 changes: 3 additions & 12 deletions lib/PuppeteerSharp/LifecycleWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal class LifecycleWatcher : IDisposable

private readonly FrameManager _frameManager;
private readonly Frame _frame;
private readonly NavigationOptions _options;
private readonly IEnumerable<string> _expectedLifecycle;
private readonly int _timeout;
private readonly string _initialLoaderId;
Expand All @@ -36,17 +35,10 @@ internal class LifecycleWatcher : IDisposable
public LifecycleWatcher(
FrameManager frameManager,
Frame frame,
int timeout,
NavigationOptions options)
WaitUntilNavigation[] waitUntil,
int timeout)
{
var waitUntil = _defaultWaitUntil;

if (options?.WaitUntil != null)
{
waitUntil = options.WaitUntil;
}

_expectedLifecycle = waitUntil.Select(w =>
_expectedLifecycle = (waitUntil ?? _defaultWaitUntil).Select(w =>
{
var protocolEvent = _puppeteerToProtocolLifecycle.GetValueOrDefault(w);
Contract.Assert(protocolEvent != null, $"Unknown value for options.waitUntil: {w}");
Expand All @@ -55,7 +47,6 @@ public LifecycleWatcher(

_frameManager = frameManager;
_frame = frame;
_options = options;
_initialLoaderId = frame.LoaderId;
_timeout = timeout;
_hasSameDocumentNavigation = false;
Expand Down

0 comments on commit aff3de2

Please sign in to comment.