-
Notifications
You must be signed in to change notification settings - Fork 22.9k
HTMLScriptElement.src - update for TrustedScriptURL #41413
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
base: main
Are you sure you want to change the base?
Conversation
- `TypeError` | ||
- : Thrown if the property is set with a string when [Trusted Types](/en-US/docs/Web/API/Trusted_Types_API) are [enforced by a CSP](/en-US/docs/Web/API/Trusted_Types_API#using_a_csp_to_enforce_trusted_types) and no default policy is defined. | ||
This is also thrown if the fetched URL cannot be successfully parsed as its indicated type, such as a module or importmap. | ||
|
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.
[mdn-linter] reported by reviewdog 🐶
|
||
- `TypeError` | ||
- : Thrown if the property is set with a string when [Trusted Types](/en-US/docs/Web/API/Trusted_Types_API) are [enforced by a CSP](/en-US/docs/Web/API/Trusted_Types_API#using_a_csp_to_enforce_trusted_types) and no default policy is defined. | ||
This is also thrown if the fetched URL cannot be successfully parsed as its indicated type, such as a module or importmap. |
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.
This isn't quite right, but I'm not sure how to be precise.
I believe it is a NetworkError on fetching. TypeError is thrown for an importmap during parsing (https://html.spec.whatwg.org/multipage/webappapis.html#import-map-authoring-requirements), and I think it is a Syntax error you get normally on parsing JavaScript.
Thoughts?
This updates the TrustedScriptURL documentation for
HTMLScriptElement/src
to include information about using it with trusted types.I don't know why/when it would ever make sense to do take an untrusted string, and if you did, to use trusted types. I've presented this primarily as "Use CSP to restrict the script options but if you have to take and untrusted script then you can use TT".
Project tracking in #37518