简体   繁体   English

如何防止browser_action每次重新加载其弹出窗口?

[英]How to prevent browser_action from reloading its popup window every time?

I'm developing a webextension and I'm stuck with following problem. 我正在开发一个网络扩展程序,但遇到以下问题。

I have browser_action that displays popup window with some content. 我有browser_action,它显示带有某些内容的弹出窗口。 The problem is, it takes 3-4 seconds to load, and user has to wait every time he opens this browser action. 问题是,加载过程需要3-4秒,并且每次打开此浏览器操作时用户都必须等待。

I want somehow force browser_action to load DOM of popup window just once , so when I open this action again it shows me already rendered window. 我想以某种方式强制browser_action 一次加载弹出窗口的DOM,所以当我再次打开此动作时,它显示我已经渲染的窗口。

I can't preload any assets through background script, because the asset is <iframe> of remote website and you can't easily store rendered DOM in localStorage just to display it later on user request. 我无法通过后台脚本预加载任何资产,因为该资产是远程网站的<iframe> ,并且您无法轻松地将渲染的DOM存储在localStorage中,只是为了稍后根据用户请求显示它。

I thought about putting <iframe> inside background script and displaying it somehow in browser_action popup window, but I failed to find out how to do that. 我曾考虑过将<iframe>放到后台脚本中,并以某种方式在browser_action弹出窗口中显示它,但是我没有找到执行该操作的方法。

Background page is loaded once and stays forever while extension is enabled, so maybe I could display it contents inside browser_action popup window somehow? 启用扩展功能后,后台页面将被加载一次并永久保留,所以也许我可以通过某种方式将其内容显示在browser_action弹出窗口中?

Unfortunately, I don't think that's not possible. 不幸的是,我认为这是不可能的。 Your best bet would be to show some useful UI while the iframe loads. 最好的选择是在加载iframe显示一些有用的UI。

It's certainly not possible to make the popup page itself be persistent. 当然不可能使弹出页面本身具有持久性。

And I'm 98% positive you can't swap in a loaded tab/frame into the page of the popup. 我有98%的肯定是您不能将已加载的选项卡/框架切换到弹出窗口的页面中。 Chrome does it internally sometimes (preload then swap, see tabs.onReplaced ), but you have little control over this mechanism. Chrome有时会在内部进行操作(预加载然后进行交换,请参见tabs.onReplaced ),但是您对此机制几乎没有控制。

It seems you can trigger it with preload links : 看来您可以通过preload链接触发它:

<link rel="preload" href="https://example.com/"
      as="document" crossorigin="anonymous">

However, it serves little purpose to embed that into the popup page (it will be fetched when the popup loads, which is milliseconds of difference) and I'm reasonably sure that preloading it from, say, the background page won't carry over to the popup, despite them normally sharing the browser process. 但是,将其嵌入到弹出页面中的目的不大(在弹出窗口加载时将被提取,这是相差的毫秒数),并且我有把握地确定,例如从后台页面预加载它不会继续弹出窗口,尽管它们通常共享浏览器进程。 You can experiment though! 您可以尝试!

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

相关问题 Chrome扩展程序从后台脚本启动browser_action弹出窗口 - Chrome extension initiate browser_action popup from background scripts 在 Chrome 扩展程序中,如何使用 browser_action (popup.html) 获取网站的 URL? - In a Chrome extension, how do I get the URL of the website with browser_action (popup.html)? 将browser_action按钮变成快捷链接而不是弹出窗口 - Turn browser_action button into shortcut link instead of popup 将变量从“浏览器操作”发送到“内容脚本” - Send variables from “browser_action” to “content_scripts” 如何设置将快捷键关联到我的Chrome扩展程序browser_action? - how to set associate a hotkey to my chrome extension browser_action? 点击时的browser_action行为。 它重新加载我的popup.html并删除sessionStorage - browser_action behaviour on click. It reloads my popup.html and deletes sessionStorage Chrome扩展程序browser_action表单 - Chrome Extension browser_action form Web 开发:如何在浏览器中“存储”页面并防止它们每次在浏览器之间导航时重新加载 - Web development: How to 'store' pages in the browsers and prevent them from reloading every time when navigating between them 如何防止每次单击按钮时重新加载javascript? - How do I prevent a javascript from reloading every time a button is click? 防止 window 在浏览器中弹出警告 - Prevent window popup warning in browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM