YouTube TrustedHTML Bypass

Bypass errors with userscripts caused by YouTube's TrustedHTML policy

  1. // ==UserScript==
  2. // @name YouTube TrustedHTML Bypass
  3. // @namespace c0d3r
  4. // @license MIT
  5. // @version 0.1
  6. // @description Bypass errors with userscripts caused by YouTube's TrustedHTML policy
  7. // @author c0d3r
  8. // @match https://www.youtube.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  10. // @run-at document-start
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // WORKAROUND: TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment.
  18. if (window.trustedTypes && trustedTypes.createPolicy) {
  19. if (!trustedTypes.defaultPolicy) {
  20. const passThroughFn = (x) => x;
  21. trustedTypes.createPolicy('default', {
  22. createHTML: passThroughFn,
  23. createScriptURL: passThroughFn,
  24. createScript: passThroughFn,
  25. });
  26. }
  27. }
  28. })();