AudioObj = new Audio;
will return “Audio is not definied”
I also tried the classic fix:
var audio = require("audio");
but with no luck. I could add audio playback in some other part of the extension than in main.js, like some content script where it works, but maybe there is a simpler and elegant solution.
new Audiocreates a new<audio>HTML element – this only works in a context that is bound to a document. SDK modules execute in a context however that has no document, consequently no DOM methods will work including this one. A work-around would be loadingabout:blankviapage-workermodule and injecting a content script there. You could then send messages to that content script and let it play audio for you whenever you need it.The alternative would be using
nsISound.play(), something along these lines:Note that
nsISoundis likely to be deprecated soon. It is an old API that is inferior to HTML5 audio.