我正在将我的扩展程序从V2迁移到V3。现在除了一个问题之外,一切都正常。在我的V2版本中,我做了:
const actualCode = '(' + function () { 'console.log("demo");' } + `)();`;
const script = document.createElement('script');
script.textContent = actualCode;
(document.head || document.documentElement).appendChild(script);
script.remove();
请注意,
console.log("demo")
只是我需要注入的内容的简化形式:)我需要注入一些JavaScript代码才能启动我的Chrome扩展程序。
但是在V3中,这种方法不再适用。我在开发工具控制台中遇到了以下错误提示。
content.js:23114
Refused to execute inline script because it violates the following
ContentSecurity Policy directive: "script-src 'self'". Either the
'unsafe-inline' keyword, a hash ('sha256-tN52+5...6d2I/Szq8='), or a nonce
('nonce-...') is required to enable inline execution.
在迁移指南中,我注意到了这个部分。
"content_security_policy": {
"extension_pages": "...",
"sandbox": "..."
}
但是那里没有太多的描述,所以对我来说这就像魔法一样。因此,我希望有人能帮助我解决这个问题?