如何在Chrome扩展程序中播放.mp3

时间:2019-06-25 09:32:34

标签: javascript google-chrome google-chrome-extension manifest.json

我正在为我们的票务系统设置自己的Chrome扩展程序。票到后,我想发出声音通知。我遇到以下错误。

我已经在清单中使用“ web_accessible_resources”嵌入了.mp3声音文件

我的MANIFEST.JSON

"manifest_version": 2,
"name": "Jingle Launcher",
"description": "Accessmenu for Jingle",
"version": "1.0.0",
"icons": {
    "128": "images/icon_128.png"
},
"browser_action": {
    "default_icon": "images/icon.png",
    "default_popup": "popup.html"
},
"content_scripts": [
    {
        "matches": [
            "https://*/*"
        ],
        "web_accessible_resources": [
            "alarm.mp3"
        ],
        "js": [
            "script.js"
        ]
    }
]

我的SCRIPT.JS

var tickets = document.getElementsByClassName('AsBlock MasterActionLink');
var myAudio = new Audio(); myAudio.src = 
chrome.extension.getURL("sounds/alarm.mp3");

if (tickets.length > 0) { myAudio.play(); }
else { console.log("Ticket not Found"); }

我收到这些错误消息

  • 获取chrome-extension://无效/ net :: ERR_FAILED
  • 未捕获(承诺)的DOMException

0 个答案:

没有答案