我试过很多种方法发挥一个声音从URL但是它不工作。
当我视察该网页有错误的控制台:
铬扩展://invalid/:1获得铬扩展://invalid/net::ERR_FAILED
未捕获的(在承诺)DOMException:未能负荷,因为没有支持的来源被发现。
清单。json:
"options_page": "./html/content.html",
"permissions": [
"activeTab",
"storage",
"contextMenus",
"http://*/*",
"https://*/*",
"tabs"
],
"web_accessible_resources": [
"*.mp3",
"*.ogg"
]
我这样做在options_page是content.html. 我还指定的'web_accessible_resources的权限脚本,但是仍然没有成功。 所有的音频链接储存在铬储存。
脚本,附在content.html:
document.addEventListener('click', function (e) {
e.preventDefault();
if (e.target.matches('.audioBtn')) {
chrome.storage.local.get({ meanifyWords: [] }, (result) => {
let getWordsObj = result.meanifyWords;
let getAudio = getWordsObj[e.target.id].audio; //getAudio="//ssl.gstatic.com/dictionary/static/sounds/20200429/experience--_gb_1.8.mp3"
let sound = new Audio(getAudio);
sound.play();
})
}
});
请告诉我任何改变上述代码,这将解决这个问题。 在此先感谢。