-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(firefox): throw error when added script blocked by CSP #1841
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -566,12 +566,19 @@ export class Frame { | |
return this._raceWithCSPError(async () => { | ||
if (url !== null) | ||
return (await context.evaluateHandleInternal(addScriptUrl, { url, type })).asElement()!; | ||
let result; | ||
if (path !== null) { | ||
let contents = await util.promisify(fs.readFile)(path, 'utf8'); | ||
contents += '//# sourceURL=' + path.replace(/\n/g, ''); | ||
return (await context.evaluateHandleInternal(addScriptContent, { content: contents, type })).asElement()!; | ||
result = (await context.evaluateHandleInternal(addScriptContent, { content: contents, type })).asElement()!; | ||
} else { | ||
result = (await context.evaluateHandleInternal(addScriptContent, { content: content!, type })).asElement()!; | ||
} | ||
return (await context.evaluateHandleInternal(addScriptContent, { content: content!, type })).asElement()!; | ||
// Another round trip to the browser to ensure that we receive CSP error messages | ||
// (if any) logged asynchronously in a separate task on the content main thread. | ||
if (this._page._delegate.cspErrorsAsynchronousForInlineScipts) | ||
await context.evaluateInternal(() => true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you found the source of this? Are we sure it is a single task? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The console logging happens in a separate task on the main thread. My assumption here is that the second evaluate is handled in its own task after the logging, so there is still a room for false positives. I could add some hooks in the native part to report the error synchronously via juggler but I felt like the problem we are fixing doesn't warrant it. |
||
return result; | ||
}); | ||
|
||
async function addScriptUrl(options: { url: string, type: string }): Promise<HTMLElement> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably do the same for inline styles and test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, styles are different. I thought the same but the styles seem to be handled asynchronously and they support onload/error events. We already have a test for this.