Skip to content

Commit

Permalink
Remove extra GetDocument function
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Apr 15, 2023
1 parent 296cb79 commit 9e58294
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp.Tests/ClickTests/ClickTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task ShouldGracefullyFailWhenPageCloses()
newPage.Mouse.ClickAsync(1, 2));
}

[PuppeteerTest("click.spec.ts", "Page.click", "should click the button after navigation ")]
[PuppeteerTest("click.spec.ts", "Page.click", "should click the button after navigation")]
[PuppeteerFact]
public async Task ShouldClickTheButtonAfterNavigation()
{
Expand Down
22 changes: 4 additions & 18 deletions lib/PuppeteerSharp/IsolatedWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ internal class IsolatedWorld
private readonly List<string> _ctxBindings = new();
private bool _detached;
private TaskCompletionSource<ExecutionContext> _contextResolveTaskWrapper = new(TaskCreationOptions.RunContinuationsAsynchronously);
private TaskCompletionSource<IElementHandle> _documentCompletionSource;
private Task _settingUpBinding;
private Task<ElementHandle> _documentTask;

Expand Down Expand Up @@ -215,25 +214,25 @@ internal async Task<JToken> EvaluateFunctionAsync(string script, params object[]

internal async Task<IElementHandle> QuerySelectorAsync(string selector)
{
var document = await GetDocument().ConfigureAwait(false);
var document = await GetDocumentAsync().ConfigureAwait(false);
return await document.QuerySelectorAsync(selector).ConfigureAwait(false);
}

internal async Task<IJSHandle> QuerySelectorAllHandleAsync(string selector)
{
var document = await GetDocument().ConfigureAwait(false);
var document = await GetDocumentAsync().ConfigureAwait(false);
return await document.QuerySelectorAllHandleAsync(selector).ConfigureAwait(false);
}

internal async Task<IElementHandle[]> QuerySelectorAllAsync(string selector)
{
var document = await GetDocument().ConfigureAwait(false);
var document = await GetDocumentAsync().ConfigureAwait(false);
return await document.QuerySelectorAllAsync(selector).ConfigureAwait(false);
}

internal async Task<IElementHandle[]> XPathAsync(string expression)
{
var document = await GetDocument().ConfigureAwait(false);
var document = await GetDocumentAsync().ConfigureAwait(false);
return await document.XPathAsync(expression).ConfigureAwait(false);
}

Expand Down Expand Up @@ -566,19 +565,6 @@ private async Task OnBindingCalled(BindingCalledResponse e)

private string GetBindingIdentifier(string name, int contextId) => $"{name}_{contextId}";

private async Task<IElementHandle> GetDocument()
{
if (_documentCompletionSource == null)
{
_documentCompletionSource = new TaskCompletionSource<IElementHandle>(TaskCreationOptions.RunContinuationsAsynchronously);
var context = await GetExecutionContextAsync().ConfigureAwait(false);
var document = await context.EvaluateExpressionHandleAsync("document").ConfigureAwait(false);
_documentCompletionSource.TrySetResult(document as IElementHandle);
}

return await _documentCompletionSource.Task.ConfigureAwait(false);
}

private string MakePredicateString(string predicate, string predicateQueryHandler)
{
var checkWaitForOptions = @"function checkWaitForOptions(
Expand Down

0 comments on commit 9e58294

Please sign in to comment.