我在 Chrome 扩展应用程序中从 MV2 迁移到 MV3 时遇到问题。
使用 MV2,通过 html 文件在 background.js 文件中实现 azure 库一切正常。
但是随着 MV3 和 background.js 文件成为服务工作者,我尝试了一些方法来使我的应用程序正常运行,但没有结果。
根据文档,我将清单文件中的后台部分切换为:
"background": {
"service_worker": "background.js",
"type": "module"
},
我通过 https://github.com/microsoft/cognitive-services-speech-sdk-js
但是当我尝试像这样将其导入background.js时:
import * as SpeechSDK from './distrib/es2015/microsoft.cognitiveservices.speech.sdk.js';
var speechConfig = SpeechSDK.SpeechConfig.fromSubscription(
"key",
"region"
);
speechConfig.speechRecognitionLanguage = "fr-FR";
speechConfig.outputFormat = SpeechSDK.OutputFormat.Detailed;
我收到错误“Service Worker 注册失败”和“获取脚本时发生未知错误”。
我根据这篇文章尝试了多种方法,例如使用包装器或 importScripts 函数: chrome 扩展 mv3 - 模块化服务工作线程 js 文件 但它们都不适合我。
您知道如何在 chrome 扩展 MV3 中使用 azure 认知服务吗?
提前致谢 !
I'm having a trouble with the migration from the MV2 to MV3 in my chrome extension application.
With the MV2, everything worked fine implementing the azure library in the background.js file through the html one.
But with the MV3 and the background.js file becoming a service worker i tried several thing to make my app functional with no results.
According to the documentation, i switched background part in the manifest file to :
"background": {
"service_worker": "background.js",
"type": "module"
},
I built the module of the azure cognitive services sdk through https://github.com/microsoft/cognitive-services-speech-sdk-js
But when i try to import it in the background.js like this :
import * as SpeechSDK from './distrib/es2015/microsoft.cognitiveservices.speech.sdk.js';
var speechConfig = SpeechSDK.SpeechConfig.fromSubscription(
"key",
"region"
);
speechConfig.speechRecognitionLanguage = "fr-FR";
speechConfig.outputFormat = SpeechSDK.OutputFormat.Detailed;
I get the error "Service worker registration failed" and "An unknown error occurred when fetching the script."
I tried multiples things like using a wrapper or the importScripts function according to this post : chrome extension mv3 - Modularize service worker js file but none of them worked for me.
Do you have any idea how to use the azure cognitive services in a chrome extension MV3 ?
Thanks in advance !
发布评论
评论(1)
在MV3中需要单独提及热权限。按照下面的代码块提及热权限。
检查 CSP 标头代码块。
background.js 中的 MV2 和 MV3 实现存在细微差别。
为了获得更好的参考,请查看以下文档。
https://developer.chrome.com/docs/extensions/mv3 /简介/mv3-迁移/
In MV3 you need to mention the hot permissions separately. Follow the below code block to mention the hot permissions.
Check the CSP headers code block.
There is a small different between MV2 and MV3 implementation in background.js
For better reference, check out the below document.
https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/