I would like to play the sound in a chrome extension. How can I do it? What should I write in myscript.js file?
I tried to write in myscript.js:
var audio = new Audio("alarm.wav"); audio.play();
and
document.write('<audio id="player" src="alarm.wav" >'); document.getElementById('player').play();
but that will not work. I didn’t add anything else, so there were no unfulfilled conditions.
My manifest.json file:
{ "name": "Alarm", "version": "1.0.0", "icons": {"64": "icon64.png"}, "permissions": [ "http://site1/", "http://site2/" ], "content_scripts": [ { "matches": ["http://site1/", "http://site2/"], "js": ["myscript.js"], "run_at": "document_end" } ], "manifest_version": 2 }
If I add a button to the site in the myscript.js file, this button works well, but I can’t play the sound. My audio file is mp3 and is in the same folder as manifest.json and myscript.js, and my myscript.js is:
var myAudio = new Audio(); myAudio.src = "alarm.mp3"; myAudio.play();
javascript google-chrome google-chrome-extension
Przemysław Niedziela
source share