getting error `This document requires 'TrustedHTML' assignment` in chrome

有些话、适合烂在心里 提交于 2020-08-25 03:48:32

问题


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

Seems like it does not accept innerHTML anymore.

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

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


回答1:


A way to avoid the error:

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)

Add a little snippet specific for the innerHTML method:

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


来源:https://stackoverflow.com/questions/61964265/getting-error-this-document-requires-trustedhtml-assignment-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!