I'm a bit new to this so if I'm missing some pertinent information I apologize.
I'm working on a Chrome Extension that uses the setInterval method to check an API and play a notification sound when a given change occurs. Right now I'm running into the error: DOMException: play() failed because the user didn't interact with the document first
I know this is something added in Chrome to prevent videos from autoplaying, I'm just wondering if there is anything I can do to get around this for the context of this extension.
content.js:
url = "https://queue.square-9.com/data/support-page.json";
//let myAudio = new Audio(chrome.runtime.getURL("coin.wav"));
var coin = new Audio("coin.wav");
//coin.crossOrigin = "anonymous";
let lastCount = 0;
let newCount = 0;
setInterval(function () {
fetch(url)
.then(function (resp) {
return resp.json();
})
.then(function (data) {
newCount = data.currentQueueCountiOS;
console.log(data.currentQueueCountiOS);
if (newCount > lastCount) {
coin.play();
console.log("New case in queue!");
}
lastCount = newCount;
});
}, 5000);
manifest.josn:
{
"manifest_version": 2,
"name": "Square9 SalesForce Notifications",
"version": "1.0.0",
"content_scripts": [
{
"matches": ["https://na156.lightning.force.com/*"],
"js": ["content.js"]
}
],
"icons": {"128": "icon_128.png"},
"browser_action": {
"default_icon": "icon.png",
"default_pop": "popup.html"
},
"permissions": ["activeTab"],
"web_accessible_resources": [
"coin.wav"
]
}
Thank you in advance for any help.