本文介绍了收到错误消息“此文档需要使用Chrome中的"TrustedHTML"分配"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个运行Angularjs 1.4的应用程序.今天早上,当我将Chrome浏览器更新为Version 83.0.4103.61

I am working on an app running Angularjs 1.4. This morning the app started crashing wit the below error when I updated my Chrome browser to Version 83.0.4103.61

似乎它不再接受innerHTML.

Seems like it does not accept innerHTML anymore.

我发现这与我们的CSP策略有关,尤其是require-trusted-types-for 'script';

I figured out it has something to do with our CSP policies especially require-trusted-types-for 'script';

随着新的chrome更新,它似乎变得更加严格.

With the new chrome update, it seems to have become stricter.

推荐答案

一种避免错误的方法:

添加CSP require-trusted-types-for 'script';trusted-types default(源于 https://w3c.github. io/webappsec-trusted-types/dist/spec/#default-policy-hdr )

Add a CSP require-trusted-types-for 'script';trusted-types default(source on https://w3c.github.io/webappsec-trusted-types/dist/spec/#default-policy-hdr)

添加一些特定于innerHTML方法的代码段:

Add a little snippet specific for the innerHTML method:

if (window.trustedTypes && window.trustedTypes.createPolicy) {
  window.trustedTypes.createPolicy('default', {
    createHTML: (string, sink) => string
  });
}

这篇关于收到错误消息“此文档需要使用Chrome中的"TrustedHTML"分配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 05:50