![](/img/trans.png)
[英]Chrome Extension (Manifest v3) call Google Apps Script deployed as WebApp with OAuth2
[英]Azure Cognitive Services sdk implementation in chrome extension manifest v3
我在 chrome 擴展應用程序中從 MV2 遷移到 MV3 時遇到問題。 使用 MV2,通過 html 實現background.js文件中的 azure 庫一切正常。 但是隨着 MV3 和background.js文件成為服務工作者,我嘗試了幾種方法使我的應用程序正常運行但沒有結果。
根據文檔,我將清單文件中的背景部分切換為:
"background": {
"service_worker": "background.js",
"type": "module"
},
我構建了 azure 認知服務模塊 sdk 通過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 function: chrome extension mv3 - Modularize service worker js file但它們都不適合我。 你知道如何在 chrome 擴展 MV3 中使用 azure 認知服務嗎? 提前致謝 !
在 MV3 中需要單獨提及熱點權限。 按照下面的代碼塊來提及熱點權限。
// Manifest V3
"permissions": [
"tabs",
"bookmarks"
],
"optional_permissions": [
"unlimitedStorage"
],
"host_permissions": [
"http://www.blogger.com/",
"*://*/*"
],
檢查 CSP 標頭代碼塊。
// Manifest V3
"content_security_policy": {
"extension_pages": "...",
"sandbox": "..."
}
background.js中的 MV2 和 MV3 實現之間存在細微差別
// Manifest V3
// manifest.json
{
"action": { … }
}
// background.js
chrome.action.onClicked.addListener(tab => { … });
為了更好地參考,請查看以下文檔。
https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.