Chrome扩展在加载前暂停 [英] Chrome extension pauses before loading

查看:125
本文介绍了Chrome扩展在加载前暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



如何减少点击扩展图标与显示内容之间的时间?

支持



我正在做一个非常简单的扩展。它一旦启动就会快速加载,但点击和弹出加载之间有点延迟。我已在这里示例扩展,您将看到完全相同的行为。

现在,如果您查看一些其他扩展程序,例如Adblock Plus,它使用了像您一样的浏览器操作图标/弹出窗口,您会看到其弹出窗口打开比
快得多。

如果您再次检查任务管理器,即使没有打开弹出窗口,您也会看到名为Extension:Adblock Plus的任务。



解释



这是因为许多扩展(如Adblock一个)正在使用持久背景页面,这是在您的扩展程序的整个生命周期中存在的单个长时间运行的脚本(直到您禁用它,关闭眉毛呃等等)

正如文档中提到的那样,不鼓励使用持久背景页面来支持活动页面(非持久活动页面)。但在你的情况下,使用事件页面并不能解决你的问题,因为当事件页面没有主动执行某些操作时,它会被卸载释放资源。 解决方案 h2>

简单的方法 $ b

在您的 manifest.json 文件将解决您的问题,但会导致内存使用量不足以保证您的扩展任务活跃(并且您的扩展程序不需要它):

 background:{
page:popup.html
},

另一种方式

提交Google提出的问题/问题。也许他们可以对这种情况进行一些优化,或者他们会为您提供更好的解决方案。你可以解释,这鼓励使用持久背景页面而不是事件: - )


Question

How do I reduce the time between clicking an extension icon and the content being displayed?

Support

I'm making a very simple extension. It loads quickly once it's started, but there is a bit of a delay between clicking and the popup loading. I've added a gif of this here. (The gif gets a bit hectic to look at, so I've put it under a link so that it doesn't burn your eyes!) It doesn't really do it justice as it loads faster on my machine than other people's for some reason.

This question (Slight loading delay with chrome extension popup) seems to address the same question, but it doesn't have an answer. I think that this question (load chrome extension popup faster) addresses this issue too, but its answer seems to be addressing a different problem.

My repo is here: https://github.com/bvn-architecture/shackleton

If I profile the load time of the extension it starts measuring from when the popup appears:

This implies that there is something on the screen about 5ms after loading. It doesn't include the pause.

解决方案

I think the delay you are facing is due to the time necessary to launch a new task process in Chrome.

Open Chrome menu > More tools > Tasks manager, you will not see any reference to your extension.
Now click on your extension browser-action icon, you will see that, after some various delay, a new entry called "Extension : BVN toolbar" will appear in the tasks manager. Once the task appears, your popup opens.

Some tests

If you test the My Bookmarks sample extension from the Chrome extension samples, you will see the exact same behavior.

Now if you have a look at some other extensions like Adblock Plus for example, which uses a browser-action icon/popup like you, you will see that its popup opens much faster than yours.
If you check the tasks manager again you will see a task named "Extension : Adblock Plus" even when the popup is not opened.

Explanations

This is because many extensions (like the Adblock one) are using persistent background pages which are single long-running scripts existing for the lifetime of your extension (until you disable it, close your browser etc.)

As mentioned in the documentation, the use of persistent background pages is discouraged in favor of event pages (non persistent ones). But in your case, using an event page will not solve your problem because when the event page is not actively doing something, it is unloaded to release resources.

Solutions

The easy way

Defining a persistent background page in your manifest.json file will solve your problem but will result in a not really necessary memory usage to keep your extension task "alive" (and your extension don't need it to work):

"background": {
    "page": "popup.html"
},

The other way

Submit the question / problem to Google. Maybe they can perform some optimizations for such case or they will provide you a better solution. And you can explain that this encourages the use of persistent background page instead of event ones :-)

这篇关于Chrome扩展在加载前暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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