简体   繁体   English

单击按钮后,Chrome扩展程序无法播放声音吗?

[英]Chrome Extension not playing sound when button is clicked?

I've created an extension for Google Chrome. 我已经为Google Chrome创建了扩展程序。 There are no errors when uploaded, and the button appears just fine on the extension bar. 上传时没有错误,并且按钮在扩展栏上显示的很好。 The extension is supposed to play a sound when clicked, but it does not. 单击该扩展名后应该会播放声音,但不会。 Here is my manifest.json file: 这是我的manifest.json文件:

{
  "manifest_version": 2,

  "name": "Extension",
  "description": "My Extension",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_title": "Extension",
    "js": ["audio.js"]
  },
  "permissions": [
    "activeTab",
    "https://ajax.googleapis.com/"
  ]
}

and here is my audio.js file: 这是我的audio.js文件:

var myAudio = new Audio();
myAudio.src = "audio.mp3";
myAudio.play();  

I don't see my issue here. 我在这里看不到我的问题。 Any and all help is appreciated! 任何和所有帮助表示赞赏!

  1. The toolbar button can only have an html file for the popup, there's no "js" parameter 工具栏按钮的弹出窗口只能有一个html文件,没有"js"参数
  2. Alternatively use a dynamically loaded event page with a click handler and omit the popup: 或者,将动态加载的事件页面与点击处理程序一起使用,并省略弹出窗口:

    manifest.json: manifest.json:

     "browser_action": { "default_icon": "icon.png", "default_title": "Extension" }, "background": { "scripts": ["event.js"], "persistent": false }, 

    event.js event.js

     chrome.browserAction.onClicked.addListener(function(tab) { var myAudio = new Audio(); myAudio.src = "audio.mp3"; myAudio.play(); }); 

See the official samples for more examples of browserAction API. 请参阅官方示例,以获取关于browserAction API的更多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM