Chrome扩展MV3拒绝加载脚本
我正在尝试创建一个可以使用Azure认知服务SDK进行文本语音的扩展名。 MV2扩展方面一切都很好,但是由于我必须迁移到MV3,所以我遇到了一些麻烦。 一步一步,我试图使一切都起作用。现在,我遇到了一个错误
拒绝加载脚本的blob:chrome-extension:// extension_id/{...}',因为它违反了以下内容安全策略指令:“ script-src'self' ”。请注意,“ script-src-elem”未明确设置,因此“脚本 - src”被用作后备书
我遇到了这个问题,因为我试图在我的网络访问资源中实现Azure SDK这是进行所有重演的iframe。 我看到有些人在谈论一个错误,有些我们无法使用外部脚本。
这是我的代码
audiosources.html
<!DOCTYPE html>
<html>
<body>
<script src="distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
<script src="audiosources.js"></script>
</body>
</html>
audiosources.js
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
switch(message.type) {
case "startStreaming":
startStreaming(message, sender, sendResponse);
break;
case "init":
console.log("init");
break;
}
sendResponse();
});
function startStreaming(message, sender, sendResponse) {
for (const tabId in Live) {
chrome.tabs.sendMessage(parseInt(tabId), {
type: "removeTranscript",
});
stopStreaming(tabId);
}
captureUser(sender.tab.id);
}
function captureUser(tabId) {
audioConfigUser = SpeechSDK.AudioConfig.fromMicrophoneInput(microphoneId);
recognizerUser = new SpeechSDK.SpeechRecognizer(
speechConfig,
audioConfigUser
);
console.log("recognizerUser : ", recognizerUser);
recognizerUser.startContinuousRecognitionAsync();
recognizerUser.recognized = (s, e) => {
toContentUser(tabId, e.result.text);
};
}
当我使用函数时,出现错误
startContinuulCognitionAsync()
subtest.json
{
"manifest_version": 3,
"version": "1",
"name": "Extension stt Azure MV3",
"minimum_chrome_version" : "93",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js",
"public/js/jquery-3.6.0.min.js"],
"css": ["public/css/index.css"]
}
],
"background": {
"service_worker" : "background.js"
},
"web_accessible_resources": [
{
"resources":["audiosources.html", "public/icons/copy_icon_24dp.png", "public/css/index.css"],
"matches":["<all_urls>"],
"use_dynamic_url": true
}
],
"permissions":["tabCapture", "tabs"],
"action":{
"default_popup":"popup.html",
"default_icon" : "./public/icons/logo.png"
}
}
感谢您的帮助!
I am trying to create an extension that can use Azure cognitive service sdk to make speech to text. Everything worked fine with the mv2 extension but since i have to migrate to mv3 i'm having some trouble.
Step by step i'm trying to make it all works. Now i'm stuck with an error
Refused to load the script 'blob:chrome-extension://extension_id/{...}' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback
I'm having this issue since i'm trying to implement the Azure sdk in my web accessible resources which is an iframe to make all the retranscription.
I saw that some people are talking about a bug, some that we can't use external script.
Here is my code
audiosources.html
<!DOCTYPE html>
<html>
<body>
<script src="distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
<script src="audiosources.js"></script>
</body>
</html>
audiosources.js
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
switch(message.type) {
case "startStreaming":
startStreaming(message, sender, sendResponse);
break;
case "init":
console.log("init");
break;
}
sendResponse();
});
function startStreaming(message, sender, sendResponse) {
for (const tabId in Live) {
chrome.tabs.sendMessage(parseInt(tabId), {
type: "removeTranscript",
});
stopStreaming(tabId);
}
captureUser(sender.tab.id);
}
function captureUser(tabId) {
audioConfigUser = SpeechSDK.AudioConfig.fromMicrophoneInput(microphoneId);
recognizerUser = new SpeechSDK.SpeechRecognizer(
speechConfig,
audioConfigUser
);
console.log("recognizerUser : ", recognizerUser);
recognizerUser.startContinuousRecognitionAsync();
recognizerUser.recognized = (s, e) => {
toContentUser(tabId, e.result.text);
};
}
the error occurs when i use the function
startContinuousRecognitionAsync()
manifest.json
{
"manifest_version": 3,
"version": "1",
"name": "Extension stt Azure MV3",
"minimum_chrome_version" : "93",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js",
"public/js/jquery-3.6.0.min.js"],
"css": ["public/css/index.css"]
}
],
"background": {
"service_worker" : "background.js"
},
"web_accessible_resources": [
{
"resources":["audiosources.html", "public/icons/copy_icon_24dp.png", "public/css/index.css"],
"matches":["<all_urls>"],
"use_dynamic_url": true
}
],
"permissions":["tabCapture", "tabs"],
"action":{
"default_popup":"popup.html",
"default_icon" : "./public/icons/logo.png"
}
}
Thanks for your help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这纯粹是Chrome Extensions的安全问题。这是一般错误。在清单中进行一些修改。由于已经信任静态数据绑定,因此需要在外部来源的动态分配。
更改subtest.js文件
检查config文件中的下图
参考
This is purely security issue with the chrome extensions. This is general error. In manifest.js do some modifications. As the static data binding is trusted already, dynamic allocation of external sources need to be whilisted.
Change in manifest.js file
Check the below in config file
Reference