Skip to content
Open
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
7 changes: 7 additions & 0 deletions lib/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ You are allowed to run git commands to update these repositories locally.
- Original Puppeteer repository: ../../puppeteer/puppeteer. Every time "upstream" is mentioned we are referring to this code.
- Bidi Driver: ../../webdriverbidi-net/webdriverbidi-net

## Upstream code structure

- Code in upstream puppeteer-core/src/api/* are our abstract class. For instance our public abstract class Frame.
- Code in upstream puppeteer-core/src/bidi/* are our Bidi* classes.
- Code in upstream puppeteer-core/src/cdp/* are our Cdp* classes.

## Project Structure

```
Expand Down Expand Up @@ -380,6 +386,7 @@ Test directory structure demonstrates comprehensive coverage:
- Headless mode variations (headless, headful, headless-shell)
- Local and upstream expectation merging
- Tests should always match the code in upstream. Tests should never be changed to match the code local code.

#### Test Server (`PuppeteerSharp.TestServer/`)
- ASP.NET Core server for hosting test pages
- wwwroot directory with test fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,21 +900,6 @@
"FAIL"
]
},
{
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
"testIdPattern": "[page.spec] *Page.addScriptTag*",
"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": "[page.spec] *addStyleTag*",
Expand Down
4 changes: 0 additions & 4 deletions lib/PuppeteerSharp.Tests/PageTests/AddScriptTagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ namespace PuppeteerSharp.Tests.PageTests
{
public class AddScriptTagTests : PuppeteerPageBaseTest
{
public AddScriptTagTests() : base()
{
}

[Test, PuppeteerTest("page.spec", "Page Page.addScriptTag", "should throw an error if no options are provided")]
public void ShouldThrowAnErrorIfNoOptionsAreProvided()
{
Expand Down
3 changes: 0 additions & 3 deletions lib/PuppeteerSharp/Bidi/BidiFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ internal BidiPage BidiPage
/// <inheritdoc />
public override Task<IElementHandle> AddStyleTagAsync(AddTagOptions options) => throw new System.NotImplementedException();

/// <inheritdoc />
public override Task<IElementHandle> AddScriptTagAsync(AddTagOptions options) => throw new System.NotImplementedException();

/// <inheritdoc />
public override async Task SetContentAsync(string html, NavigationOptions options = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/Bidi/BidiRealm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private async Task<EvaluateResultSuccess> EvaluateAsync(bool returnByValue, bool
if (result.ResultType == EvaluateResultType.Exception)
{
// TODO: Improve text details
throw new EvaluateException(((EvaluateResultException)result).ExceptionDetails.Text);
throw new EvaluationFailedException(((EvaluateResultException)result).ExceptionDetails.Text);
}

return result as EvaluateResultSuccess;
Expand Down
66 changes: 0 additions & 66 deletions lib/PuppeteerSharp/Cdp/CdpFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,72 +243,6 @@ public override async Task<IElementHandle> AddStyleTagAsync(AddTagOptions option
return (await MainRealm.TransferHandleAsync(handle).ConfigureAwait(false)) as IElementHandle;
}

/// <inheritdoc/>
public override async Task<IElementHandle> AddScriptTagAsync(AddTagOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

if (string.IsNullOrEmpty(options.Url) && string.IsNullOrEmpty(options.Path) &&
string.IsNullOrEmpty(options.Content))
{
throw new ArgumentException("Provide options with a `Url`, `Path` or `Content` property");
}

var content = options.Content;

if (!string.IsNullOrEmpty(options.Path))
{
content = await AsyncFileHelper.ReadAllText(options.Path).ConfigureAwait(false);
content += "//# sourceURL=" + options.Path.Replace("\n", string.Empty);
}

var handle = await IsolatedRealm.EvaluateFunctionHandleAsync(
@"async (puppeteerUtil, url, id, type, content) => {
const createDeferredPromise = puppeteerUtil.createDeferredPromise;
const promise = createDeferredPromise();
const script = document.createElement('script');
script.type = type;
script.text = content;
if (url) {
script.src = url;
script.addEventListener(
'load',
() => {
return promise.resolve();
},
{once: true}
);
script.addEventListener(
'error',
event => {
promise.reject(
new Error(event.message ?? 'Could not load script')
);
},
{once: true}
);
} else {
promise.resolve();
}
if (id) {
script.id = id;
}
document.head.appendChild(script);
await promise;
return script;
}",
new LazyArg(async context => await context.GetPuppeteerUtilAsync().ConfigureAwait(false)),
options.Url,
options.Id,
options.Type,
content).ConfigureAwait(false);

return (await MainRealm.TransferHandleAsync(handle).ConfigureAwait(false)) as IElementHandle;
}

internal void UpdateClient(CDPSession client, bool keepWorlds = false)
{
Client = client;
Expand Down
68 changes: 66 additions & 2 deletions lib/PuppeteerSharp/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using PuppeteerSharp.Helpers;
using PuppeteerSharp.Input;
using PuppeteerSharp.QueryHandlers;

Expand Down Expand Up @@ -196,14 +197,77 @@ public async Task<IElementHandle[]> XPathAsync(string expression)
}

/// <inheritdoc/>
public Task<DeviceRequestPrompt> WaitForDevicePromptAsync(WaitForOptions options = default)
public Task<DeviceRequestPrompt> WaitForDevicePromptAsync(WaitForOptions options = null)
=> GetDeviceRequestPromptManager().WaitForDevicePromptAsync(options);

/// <inheritdoc/>
public abstract Task<IElementHandle> AddStyleTagAsync(AddTagOptions options);

/// <inheritdoc/>
public abstract Task<IElementHandle> AddScriptTagAsync(AddTagOptions options);
public async Task<IElementHandle> AddScriptTagAsync(AddTagOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

if (string.IsNullOrEmpty(options.Url) && string.IsNullOrEmpty(options.Path) &&
string.IsNullOrEmpty(options.Content))
{
throw new ArgumentException("Provide options with a `Url`, `Path` or `Content` property");
}

var content = options.Content;

if (!string.IsNullOrEmpty(options.Path))
{
content = await AsyncFileHelper.ReadAllText(options.Path).ConfigureAwait(false);
content += "//# sourceURL=" + options.Path.Replace("\n", string.Empty);
}

var handle = await IsolatedRealm.EvaluateFunctionHandleAsync(
@"async (puppeteerUtil, url, id, type, content) => {
const createDeferredPromise = puppeteerUtil.createDeferredPromise;
const promise = createDeferredPromise();
const script = document.createElement('script');
script.type = type;
script.text = content;
if (url) {
script.src = url;
script.addEventListener(
'load',
() => {
return promise.resolve();
},
{once: true}
);
script.addEventListener(
'error',
event => {
promise.reject(
new Error(event.message ?? 'Could not load script')
);
},
{once: true}
);
} else {
promise.resolve();
}
if (id) {
script.id = id;
}
document.head.appendChild(script);
await promise;
return script;
}",
new LazyArg(async context => await context.GetPuppeteerUtilAsync().ConfigureAwait(false)),
options.Url,
options.Id,
options.Type,
content).ConfigureAwait(false);

return (await MainRealm.TransferHandleAsync(handle).ConfigureAwait(false)) as IElementHandle;
}

/// <inheritdoc/>
public Task<string> GetContentAsync(GetContentOptions options = null)
Expand Down
Loading