简体   繁体   English

Chrome扩展程序保持弹出窗口加载

[英]Chrome Extension keep popup loaded

I'm working on a extension for some internet radio station. 我正在为一些互联网广播电台做扩展。 Currently its opening new window to play music, but I want to make an extension. 目前它打开了播放音乐的新窗口,但是我想扩展一下。

I created popup and put the URL of internet radio station inside it as an iframe. 我创建了弹出窗口,并将互联网广播电台的网址作为iframe放在其中。 The problem is, when the popup closes, the iframe also closes and music stops, which is kinda sad. 问题是,当弹出窗口关闭时,iframe也关闭并且音乐停止,这有点让人难过。

Any ideas on how to keep the content of popup loaded even while it is "closed" ? 关于如何在“关闭”状态下仍保持弹出内容加载的任何想法?

Set the manifest to have 将清单设置为

"background": {
    "scripts": ["background.js"]
 },

Then you can load the script this way once you execute the page popup the script will run. 然后,您可以在执行页面弹出窗口后以这种方式加载脚本,脚本将运行。

If you do this i would suggest adding key commands to stop,pause and play the command like so to your manifest. 如果执行此操作,我建议您添加关键命令以停止,暂停并播放清单中的命令。

 "commands": {
      "commands": {
      "Play": {
        "suggested_key": {
          "default": "Ctrl+Shift+U",
          "mac": "Command+Shift+U"
        },
        "description": "Toggle feature foo"
      },
      "Stop": {
        "suggested_key": {
          "default": "Ctrl+Shift+Z",
          "mac": "Command+Shift+D"
        },
        "description": "Toggle feature foo"
      }
  }

Then in your background file that you set in the manifest add a chrome listener 然后在清单中设置的背景文件中添加镶边监听器

 chrome.commands.onCommand.addListener(function(command) {
    console.log('Command:', command);
    if(command == "Play"){
        //play function here
    }else if(command == "Stop"){
        //stop function here
    }
 });

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

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