是否可以从另一个进程(也许通过扩展)外部触发 Google Chrome 中的 Javascript?
我希望我的计算机上的本地进程能够在本地 Google Chrome 浏览器的特定选项卡中触发 javascript。该选项卡未连接到本地主机,而是连接到另一个已知域。
这可能听起来有点奇怪,但我实际上想做的是允许通过全局操作系统键盘快捷键控制我的浏览器内音乐播放器,这样我就不必转到 Chrome 中的选项卡来暂停或跳过例如,一条轨道。
我在任何地方都找不到任何对此类行为的引用。以下是我迄今为止想到的一些解决方案:
- 我尝试查看 Chrome 扩展 API,并找到了 NPAPI 插件 似乎允许 javascript 触发外部进程,但我不确定是否可以让它以相反的方式工作?
- 如果无法直接触发 javascript,我可能会考虑打开一个 HTML5 WebSocket 到一个小型本地主机网络服务器,该服务器可以将控制消息推送到浏览器。我读到 WebSockets 可以通过这种方式跨域运行。
- 如果上述两种方法都不起作用,我总是可以将本地主机进程推送到远程服务器,该服务器可以通过 WebSockets 或其他回调方法将消息转发回我的 Chrome 选项卡。我真的希望我能避免这种情况。
我忽略的 Chrome 扩展程序中是否有可以从外部触发的功能?或者 NPAPI 插件能够实现我想要的功能吗?或者是否有更好的解决方案?对于这样一个简单的任务来说,这些似乎都有点不必要的复杂。
I'd like a local process on my machine to be able to trigger javascript in a specific tab in my local Google Chrome browser. The tab is not connecting to localhost, but to another known domain.
This may sound a bit weird, but what I'm actually trying to do is allow my in-browser music player to be controlled via global OS keyboard shortcuts, so I don't have to go to my tab in Chrome to pause or skip a track, for example.
I haven't been able to find any references to this type of behavior anywhere. Here are some solutions I've though of so far:
- I tried looking at the Chrome Extensions APIs, and found the NPAPI Plugins which seem to allow javascript to trigger an external process, but I'm not sure if I could get it to work in the opposite way?
- If directly triggering javascript is not possible, I may look into opening an HTML5 WebSocket to a tiny localhost webserver that can push control messages to the browser. I've read that WebSockets can function cross-domain in this way.
- If both of the above don't work, I could always have a localhost process push to the remote server, which can forward the message back to my Chrome tab via WebSockets or another callback method. I really hope I can avoid this.
Are there features of Chrome extensions I'm overlooking that can be triggered externally? Or will a NPAPI plugin be able to do what I want? Or is there a better solution for this somehow? These all seem a little needlessly complex for such a simple task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用 NPAPI 插件,因为它也是最适合您所做的事情的插件。
祝你好运完成它。
I would use the NPAPI Plugin becasue it is the best one too use for the thing your doing.
Good luck completing it.