Skip to content

Commit

Permalink
add default policy if one doesn't exist (#489)
Browse files Browse the repository at this point in the history
* add default policy if one doesn't exist

* revert speculative fix commit

* add comment linking chrome tests
  • Loading branch information
s-cork authored Aug 9, 2024
1 parent ad722fe commit 2cd7338
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions extension/src/pages/youtube-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ declare global {
let trustedPolicy: any = undefined;

if (window.trustedTypes !== undefined) {
trustedPolicy = window.trustedTypes.createPolicy('passThrough', {
createHTML: (s: string) => s,
createScript: (s: string) => s,
createScriptURL: (s: string) => s,
});

// YouTube doesn't define a default policy
// we create a default policy to avoid errors that seem to be caused by chrome not supporting trustedScripts in Function sinks
// If YT enforce a strict default policy in the future, we may need to revisit this
// hopefully by then chrome will have fixed the issue: https://wpt.fyi/results/trusted-types/eval-function-constructor.html
// (in chrome 127 the final test was failing)
if (window.trustedTypes.defaultPolicy === null) {
window.trustedTypes.createPolicy('default', {
createHTML: (s: string) => s,
createScript: (s: string) => s,
createScriptURL: (s: string) => s,
});
}
trustedPolicy = window.trustedTypes.createPolicy('passThrough', {
createHTML: (s: string) => s,
createScript: (s: string) => s,
});
}

document.addEventListener(
Expand Down

0 comments on commit 2cd7338

Please sign in to comment.