Skip to content

Commit

Permalink
fix add script code
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Apr 15, 2023
1 parent 4e87c48 commit 4846607
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/PuppeteerSharp.Tests/PageTests/AddStyleTagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public async Task ShouldWorkWithAUrl()
public async Task ShouldThrowAnErrorIfLoadingFromUrlFail()
{
await Page.GoToAsync(TestConstants.EmptyPage);
var exception = await Assert.ThrowsAsync<PuppeteerException>(()
var exception = await Assert.ThrowsAnyAsync<PuppeteerException>(()
=> Page.AddStyleTagAsync(new AddTagOptions { Url = "/nonexistfile.js" }));
Assert.Equal("Loading style from /nonexistfile.js failed", exception.Message);
Assert.Contains("Could not load style", exception.Message);
}

[PuppeteerTest("page.spec.ts", "Page.addStyleTag", "should work with a path")]
Expand Down Expand Up @@ -99,7 +99,7 @@ public async Task ShouldThrowWhenAddedWithContentToTheCSPPage()
public async Task ShouldThrowWhenAddedWithURLToTheCSPPage()
{
await Page.GoToAsync(TestConstants.ServerUrl + "/csp.html");
var exception = await Assert.ThrowsAsync<PuppeteerException>(
var exception = await Assert.ThrowsAnyAsync<PuppeteerException>(
() => Page.AddStyleTagAsync(new AddTagOptions
{
Url = TestConstants.CrossProcessUrl + "/injectedstyle.css"
Expand Down
10 changes: 5 additions & 5 deletions lib/PuppeteerSharp/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ public async Task<IElementHandle> AddStyleTagAsync(AddTagOptions options)
@"async (puppeteerUtil, url, id, type, content) => {
const createDeferredPromise = puppeteerUtil.createDeferredPromise;
const promise = createDeferredPromise();
let element: HTMLStyleElement | HTMLLinkElement;
let element;
if (!url) {
element = document.createElement('style');
element.appendChild(document.createTextNode(content!));
element.appendChild(document.createTextNode(content));
} else {
const link = document.createElement('link');
link.rel = 'stylesheet';
Expand All @@ -225,7 +225,7 @@ public async Task<IElementHandle> AddStyleTagAsync(AddTagOptions options)
event => {
promise.reject(
new Error(
(event as ErrorEvent).message ?? 'Could not load style'
event.message ?? 'Could not load style'
)
);
},
Expand All @@ -235,7 +235,7 @@ public async Task<IElementHandle> AddStyleTagAsync(AddTagOptions options)
await promise;
return element;
}",
PuppeteerWorld.PuppeteerUtil,
await PuppeteerWorld.PuppeteerUtil.ConfigureAwait(false),
options.Url,
options.Id,
options.Type,
Expand Down Expand Up @@ -300,7 +300,7 @@ public async Task<IElementHandle> AddScriptTagAsync(AddTagOptions options)
await promise;
return script;
}",
PuppeteerWorld.PuppeteerUtil,
await PuppeteerWorld.PuppeteerUtil.ConfigureAwait(false),
options.Url,
options.Id,
options.Type,
Expand Down

0 comments on commit 4846607

Please sign in to comment.