Siki-Siki
Siki-Siki

Reputation: 113

Chrome extension simple audio

I would like to play a simple "alarm" in chrome extension but i have and error in console: "GET chrome-extension://invalid/ net::ERR_FAILED chrome-extension://invalid/:1" My simple code is:

var asdasd = '<span id="audio"></span>';
$('body').append(asdasd);
var srcaudio = chrome.extension.getURL('alert2.mp3'); 
$('#audio').html('<audio autoplay><source src="'+srcaudio+'"></audio>');

And my manifest is:

{
  "manifest_version": 2,
  "name": "test",
  "description": "test",
  "version": "1.0",
  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js": ["jquery.js","myscript.js"]
    }
  ]
}

Upvotes: 0

Views: 230

Answers (1)

Pavlo
Pavlo

Reputation: 1197

So i tried to do this in my own extension.

As wOxxOm said, you probably need web_asseible_resources. For me the css/js/fonts are in the assets package. I dunno where you placed it.

"web_accessible_resources": [
    "assets/css/*",
    "assets/js/*",
    "assets/fonts/*"
  ]

Secondly, extension.getUrl() is deprecated, so use runtime.getUrl() instead, as for the url try to use "./alert2.mp3" or "~/alert2.mp3" if the direct path isn't working

Upvotes: 2

Related Questions