谷歌浏览器扩展程序:如何通过弹出页面上的iframe查看后台页面? [英] Google Chrome Extension: How can I view a background page via an iframe on the popup page?

查看:754
本文介绍了谷歌浏览器扩展程序:如何通过弹出页面上的iframe查看后台页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试一段时间,无法让这个工作。
基本上,当扩展启用时,我想要一个持久页面(不管浏览器动作图标是否被点击,它都会持有套接字连接)。

I've been trying for a while now and can't get this to work. Basically, when the extension is enabled, I want a persistent page (That will hold a socket connection regardless of whether the Browser Action icon is clicked).

后台页面以这种方式运行。现在,我想让这个背景页面显示在弹出页面中(通过iframe或其他替代方法,以便它不是Background页面的另一个实例。)

The background page functions in this way. Now, I want this background page to show in the popup page (via iframe or any alternative so that it's not another instance of the Background page.

当我尝试:
chrome-extension:// invalid /的网页可能会暂时关闭,或者它可能已永久移动到新的网址。

I get something like this when I try: "The webpage at chrome-extension://invalid/ might be temporarily down or it may have moved permanently to a new web address."

关于我可以尝试的方向的任何想法?

Any ideas on a direction I could try?

推荐答案

真正的背景页面是隐藏的,无法显示可以通过点击 chrome:// extensions / 中的 background.html 链接打开后台页面的工具,在开发者模式下)。

The real background page is hidden, and cannot be shown (the Dev Tools for the background page can be opened by clicking on the background.html link at chrome://extensions/, in Developer mode).

在弹出窗口中,您可以使用 chrome.extension.getBackgroundPage() 。保持(会话)持久状态您的扩展程序的弹出窗口。

From the popup, you can directly access methods and properties from the background page, using chrome.extension.getBackgroundPage(). This can be used to maintain a (session-)persistent state of your extension's popup window.

当您尝试在框架/选项卡中加载背景页面时,会显示该页面的新 实例。但是,这是不是背景页面。它被视为扩展名中的普通HTML文件。

When you try to load the background page in a frame/tab, a new instance of the page is shown. This, however, is not a background page. It's treated as a normal HTML file within your extension.

这篇关于谷歌浏览器扩展程序:如何通过弹出页面上的iframe查看后台页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆