问题
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