Skip to content

[BUG] 插件JS crash: Failed to execute 'parseFromString' on 'DOMParser': This document requires 'TrustedHTML' assignment. #1239

Closed
2 of 2 issues completed

Description

@fireattack

问题描述

在运行某脚本的某个功能时, scriptcat自己的 content js 崩溃了,提示 This document requires 'TrustedHTML' assignment.

重现步骤

  1. 安装此脚本: https://github.com/qsniyg/maxurl/raw/refs/heads/master/userscript_smaller.user.js
  2. 打开 https://docs.google.com/forms/d/e/1FAIpQLSeAGfm0UUoQbBQnGR1fT8YcXJZvxaSYJTHUY_SqFt295RVVCA/viewform
  3. 使用这个脚本的这个功能:
Image
  1. 0b4675ed-54fa-4f5e-97aa-c0c3fd50cc35 这个scriptcat自带的js崩溃

脚本猫版本

1.2.4

操作系统以及浏览器信息

Win10, Chrome 144.0.7559.133 (Official Build) (64-bit) (cohort: Stable)

补充信息 (选填)

报错信息(网页的console):

32eff70a-ec41-43da-bb73-dc22c6861c8c:2 This document requires 'TrustedHTML' assignment. The action has been blocked.
get responseXML	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
shallowcopy_obj	@	Image Max URL.user.js:3064
shallowcopy	@	Image Max URL.user.js:3079
data.onload	@	Image Max URL.user.js:2137
n	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
Z	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
(anonymous)	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
R	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
(anonymous)	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
a.emit	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
messageHandle	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
(anonymous)	@	32eff70a-ec41-43da-bb73-dc22c6861c8c:2
nativeSend	@	4460e46c-3b1c-40bc-8132-95cb9aeb7620:2
postMessage	@	4460e46c-3b1c-40bc-8132-95cb9aeb7620:2
sendMessage	@	4460e46c-3b1c-40bc-8132-95cb9aeb7620:2
(anonymous)	@	4460e46c-3b1c-40bc-8132-95cb9aeb7620:2


Uncaught (in promise) TypeError: Failed to execute 'parseFromString' on 'DOMParser': This document requires 'TrustedHTML' assignment.
    at get responseXML (32eff70a-ec41-43da-bb73-dc22c6861c8c:2:19444)
    at Object.assign (<anonymous>)
    at shallowcopy_obj (Image Max URL.user.js:3064:18)
    at shallowcopy (Image Max URL.user.js:3079:12)
    at data.onload (Image Max URL.user.js:2137:18)
    at n (32eff70a-ec41-43da-bb73-dc22c6861c8c:2:21025)
    at Z (32eff70a-ec41-43da-bb73-dc22c6861c8c:2:15701)
    at 32eff70a-ec41-43da-bb73-dc22c6861c8c:2:22241
    at new Promise (<anonymous>)
    at R (32eff70a-ec41-43da-bb73-dc22c6861c8c:2:22089)

Activity

  1. added theissue type on Feb 13, 2026
  2. cyfung1031 commented on Feb 13, 2026

    @cyfung1031
    Collaborator

    TTP issue


    后记:
    一般使用者其实也可以用比较简单的方法解决这个问题。只要安装一些专门处理 TTP 的用户脚本就可以了,例如这个脚本:
    https://scriptcat.org/zh-CN/script-show-page/5410

  3. cyfung1031 commented on Feb 13, 2026

    @cyfung1031
    Collaborator

    先讲结论

    跟 Tampermonkey 做法一样。不会在 UserScript Manager 层面处理

  4. fireattack commented on Feb 13, 2026

    @fireattack
    Author

    不太懂这方面,不过我看你发的那个 issue 写的 fixed?

    如果功能处理不了,感觉至少可以 handle 一下 error 让脚本不要 crash?

  5. cyfung1031 commented on Feb 13, 2026

    @cyfung1031
    Collaborator

    解决方法有两个

    1. 在你写的 UserScript 处理。 上面 TM issue 有个基础版。不过我建议使用我的增强版,避免脚本间互相冲突

    https://greasyfork.org/scripts/522884-default-trusted-types-policy-for-all-pages/
    https://greasyfork.org/scripts/522884-default-trusted-types-policy-for-all-pages/code
    ( 你也可以把这个脚本直接安装它。一步解决)

    if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
      let s = s => s, [p, q, r] = [s, s, s]; s = trustedTypes;
      s.createPolicy('default', { createHTML: s => p(s), createScriptURL: s => q(s), createScript: s => r(s) });
      s.$Ω = s.createPolicy;
      s.createPolicy = function (a, b) {
        if (a === 'default' && s) {
          s = 0;
          const { createHTML: x, createScriptURL: y, createScript: z } = b;
          x && (p = x);
          y && (q = y);
          z && (r = z);
          return this.defaultPolicy;
        }
        return this.$Ω(...arguments);
      };
    }
    1. 把你的脚本加 //@inject-into content. 具体说明: https://violentmonkey.github.io/posts/inject-into-context/
  6. cyfung1031 commented on Feb 13, 2026

    @cyfung1031
    Collaborator

    不太懂这方面,不过我看你发的那个 issue 写的 fixed?

    如果功能处理不了,感觉至少可以 handle 一下 error 让脚本不要 crash?

    里面的讨论很长。标题那个问题确实fixed,但你说的这个还存在

    VM那边也是直接关掉Issue的。 ScriptCat也是不会在 UserScript Manager 层面处理

    violentmonkey/violentmonkey#1873

    也有很多零零碎碎的相关讨论

    如果你是使用者,不懂代码,直接安装 https://greasyfork.org/scripts/522884-default-trusted-types-policy-for-all-pages/ 就好

  7. fireattack commented on Feb 13, 2026

    @fireattack
    Author

    好的谢谢

  8. fireattack commented on Feb 13, 2026

    @fireattack
    Author

    不太懂这方面,不过我看你发的那个 issue 写的 fixed?
    如果功能处理不了,感觉至少可以 handle 一下 error 让脚本不要 crash?

    里面的讨论很长。标题那个问题确实fixed,但你说的这个还存在

    VM那边也是直接关掉Issue的。 ScriptCat也是不会在 UserScript Manager 层面处理

    violentmonkey/violentmonkey#1873

    也有很多零零碎碎的相关讨论

    如果你是使用者,不懂代码,直接安装 https://greasyfork.org/scripts/522884-default-trusted-types-policy-for-all-pages/ 就好

    但是我在楼主说的这个步骤,使用 Chrome + tampermonkey,是可以正常不报错的(没有安装你提供的 "Default Trusted Types Policy for All Pages").

  9. CodFrm commented on Feb 13, 2026

    @CodFrm
    Member

    我试了一下 TM 可以正常运行,我先打开,后面再研究一下

  10. reopened this on Feb 13, 2026
  11. self-assigned this
    on Feb 13, 2026
  12. cyfung1031 commented on Feb 13, 2026

    @cyfung1031
    Collaborator

    找到问题了。确实在ScriptCat的代码(我写的部份)有别的问题。我会处理

    暂时你可以用 Default Trusted Types Policy for All Pages 解决。

    我也把脚本上载到 脚本猫的网站了
    https://scriptcat.org/zh-CN/script-show-page/5410

  13. cyfung1031 commented on Feb 14, 2026

    @cyfung1031
    Collaborator

    找到问题了。确实在ScriptCat的代码(我写的部份)有别的问题。我会处理

    暂时你可以用 Default Trusted Types Policy for All Pages 解决。

    我也把脚本上载到 脚本猫的网站了 https://scriptcat.org/zh-CN/script-show-page/5410

    @CodFrm @fireattack

    简单说明一下
    这个 issue 是因为

    1. 有两个ScriptCat内部处理跟Tampermonkey内部处理不一致
    2. "Image Max URL" 本身的代码触发了这些内部处理不一致
    3. 在TTP页面 ( https://docs.google.com/forms/... )时很不幸这些内部处理不一致会使ScriptCat坏掉

    那个 This document requires 'TrustedHTML' assignment. 的问题,其实在 Tampermonkey 也有,只是没有在 "Image Max URL" 使用时触发出来

    PR已经提交了。不过作者最近忙又对于复杂的代码表示抗拒。 不清楚什么时候会修好

  14. cyfung1031 commented on Feb 16, 2026

    @cyfung1031
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

compatibility其它管理器可以运行,脚本猫不能运行

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions