简体   繁体   English

弹出式窗口中的Chrome扩展程序后台页面

[英]Chrome extension background page in popup

Say I want to make a chrome extension that plays audio or video that you can play/pause. 假设我想制作一个Chrome扩展程序,以播放可以播放/暂停的音频或视频。 Extension page is being open from a popup. 扩展页面正在从弹出窗口中打开。 It should be available on any tab that you go to. 它应该在您转到的任何选项卡上都可用。

As I understand chrome limits you to the background page that is being run like a separate tab, but cannot be visible and a popup page that gets displayed once you click on the icon. 据我了解,chrome将您限制为正在运行的背景页面,就像一个单独的选项卡一样,但无法显示,并且单击该图标后便会显示一个弹出页面。

So I wanted to know how would you go on about it. 所以我想知道你会怎么做。 Insofar I see it in hackish ways like: 就目前而言,我以骇人的方式看到它:

  • background -> event -> popup (audio context + "fake" audio buffer player) 背景->事件->弹出窗口(音频上下文+“假”音频缓冲播放器)
  • background -> localStorage -> popup (same thing) 背景-> localStorage->弹出窗口(相同的内容)

Are there alternative solutions to this? 是否有其他解决方案?

Not really. 并不是的。 If you want to run an audio independently of any open tab, you have to run it in the background page. 如果要独立于任何打开的选项卡运行音频,则必须在后台页面中运行它。

Then you can show any kind of UI, for instance in the popup, with your custom controls. 然后,您可以使用自定义控件显示任何类型的UI,例如在弹出窗口中。 Then, use Messaging to control the background page / update your controls in the UI. 然后,使用“ 消息传递”来控制后台页面/在UI中更新控件。

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

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