I tried many ways to play a sound from the URL but it isn’t working.
When I inspected the page have errors console:
chrome-extension://invalid/:1 GET chrome-extension://invalid/ net::ERR_FAILED
Uncaught (in promise) DOMException: Failed to load because no supported source was found.
manifest.json:
JavaScript
x
14
14
1
"options_page": "./html/content.html",
2
"permissions": [
3
"activeTab",
4
"storage",
5
"contextMenus",
6
"http://*/*",
7
"https://*/*",
8
"tabs"
9
],
10
"web_accessible_resources": [
11
"*.mp3",
12
"*.ogg"
13
]
14
I’m doing this in options_page that is content.html. I have also given ‘web_accessible_resources’ permission to the script, but still no success. All the audio links are stored in chrome storage.
Script that’s attached in content.html:
JavaScript
1
12
12
1
document.addEventListener('click', function (e) {
2
e.preventDefault();
3
if (e.target.matches('.audioBtn')) {
4
chrome.storage.local.get({ meanifyWords: [] }, (result) => {
5
let getWordsObj = result.meanifyWords;
6
let getAudio = getWordsObj[e.target.id].audio; //getAudio="//ssl.gstatic.com/dictionary/static/sounds/20200429/experience--_gb_1.8.mp3"
7
let sound = new Audio(getAudio);
8
sound.play();
9
})
10
}
11
});
12
Please point me to any changes in the above code that will solve this problem. Thanks in advance.
Advertisement
Answer
Add schema to URL:
JavaScript
1
2
1
let getAudio = "https:" + getWordsObj[e.target.id].audio;
2