I would like to play sound in 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 it does not work. I did not add anything more, so there are 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 button to site in myscript.js file, this button works well, but i can't play 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();