Skip to content

Commit c20fb14

Browse files
committed
fix
1 parent af9e6c9 commit c20fb14

File tree

4 files changed

+43
-34
lines changed

4 files changed

+43
-34
lines changed

lib/CLAUDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ You are allowed to run git commands to update these repositories locally.
1414
- Original Puppeteer repository: ../../puppeteer/puppeteer. Every time "upstream" is mentioned we are referring to this code.
1515
- Bidi Driver: ../../webdriverbidi-net/webdriverbidi-net
1616

17+
## Upstream code structure
18+
19+
- Code in upstream puppeteer-core/src/api/* are our abstract class. For instance our public abstract class Frame.
20+
- Code in upstream puppeteer-core/src/bidi/* are our Bidi* classes.
21+
- Code in upstream puppeteer-core/src/cdp/* are our Cdp* classes.
22+
1723
## Project Structure
1824

1925
```
@@ -380,6 +386,7 @@ Test directory structure demonstrates comprehensive coverage:
380386
- Headless mode variations (headless, headful, headless-shell)
381387
- Local and upstream expectation merging
382388
- Tests should always match the code in upstream. Tests should never be changed to match the code local code.
389+
383390
#### Test Server (`PuppeteerSharp.TestServer/`)
384391
- ASP.NET Core server for hosting test pages
385392
- wwwroot directory with test fixtures

lib/PuppeteerSharp.Tests/PageTests/AddScriptTagTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ namespace PuppeteerSharp.Tests.PageTests
88
{
99
public class AddScriptTagTests : PuppeteerPageBaseTest
1010
{
11-
public AddScriptTagTests() : base()
12-
{
13-
}
14-
1511
[Test, PuppeteerTest("page.spec", "Page Page.addScriptTag", "should throw an error if no options are provided")]
1612
public void ShouldThrowAnErrorIfNoOptionsAreProvided()
1713
{

lib/PuppeteerSharp/Bidi/BidiRealm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private async Task<EvaluateResultSuccess> EvaluateAsync(bool returnByValue, bool
214214
if (result.ResultType == EvaluateResultType.Exception)
215215
{
216216
// TODO: Improve text details
217-
throw new EvaluateException(((EvaluateResultException)result).ExceptionDetails.Text);
217+
throw new EvaluationFailedException(((EvaluateResultException)result).ExceptionDetails.Text);
218218
}
219219

220220
return result as EvaluateResultSuccess;

lib/PuppeteerSharp/Frame.cs

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Text.Json;
44
using System.Threading.Tasks;
55
using Microsoft.Extensions.Logging;
6+
using PuppeteerSharp.Helpers;
67
using PuppeteerSharp.Input;
78
using PuppeteerSharp.QueryHandlers;
89

@@ -196,7 +197,7 @@ public async Task<IElementHandle[]> XPathAsync(string expression)
196197
}
197198

198199
/// <inheritdoc/>
199-
public Task<DeviceRequestPrompt> WaitForDevicePromptAsync(WaitForOptions options = default)
200+
public Task<DeviceRequestPrompt> WaitForDevicePromptAsync(WaitForOptions options = null)
200201
=> GetDeviceRequestPromptManager().WaitForDevicePromptAsync(options);
201202

202203
/// <inheritdoc/>
@@ -220,45 +221,50 @@ public async Task<IElementHandle> AddScriptTagAsync(AddTagOptions options)
220221

221222
if (!string.IsNullOrEmpty(options.Path))
222223
{
223-
content = await Helpers.AsyncFileHelper.ReadAllText(options.Path).ConfigureAwait(false);
224+
content = await AsyncFileHelper.ReadAllText(options.Path).ConfigureAwait(false);
224225
content += "//# sourceURL=" + options.Path.Replace("\n", string.Empty);
225226
}
226227

227-
var type = options.Type ?? "text/javascript";
228-
229228
var handle = await IsolatedRealm.EvaluateFunctionHandleAsync(
230-
@"async ({url, id, type, content}) => {
231-
return await new Promise((resolve, reject) => {
232-
const script = document.createElement('script');
233-
script.type = type;
234-
script.text = content;
229+
@"async (puppeteerUtil, url, id, type, content) => {
230+
const createDeferredPromise = puppeteerUtil.createDeferredPromise;
231+
const promise = createDeferredPromise();
232+
const script = document.createElement('script');
233+
script.type = type;
234+
script.text = content;
235+
if (url) {
236+
script.src = url;
237+
script.addEventListener(
238+
'load',
239+
() => {
240+
return promise.resolve();
241+
},
242+
{once: true}
243+
);
235244
script.addEventListener(
236245
'error',
237246
event => {
238-
reject(new Error(event.message ?? 'Could not load script'));
247+
promise.reject(
248+
new Error(event.message ?? 'Could not load script')
249+
);
239250
},
240251
{once: true}
241252
);
242-
if (id) {
243-
script.id = id;
244-
}
245-
if (url) {
246-
script.src = url;
247-
script.addEventListener(
248-
'load',
249-
() => {
250-
resolve(script);
251-
},
252-
{once: true}
253-
);
254-
document.head.appendChild(script);
255-
} else {
256-
document.head.appendChild(script);
257-
resolve(script);
258-
}
259-
});
253+
} else {
254+
promise.resolve();
255+
}
256+
if (id) {
257+
script.id = id;
258+
}
259+
document.head.appendChild(script);
260+
await promise;
261+
return script;
260262
}",
261-
new { url = options.Url, id = options.Id, type, content }).ConfigureAwait(false);
263+
new LazyArg(async context => await context.GetPuppeteerUtilAsync().ConfigureAwait(false)),
264+
options.Url,
265+
options.Id,
266+
options.Type,
267+
content).ConfigureAwait(false);
262268

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

0 commit comments

Comments
 (0)