轻微的加载延迟与铬扩展弹出

编程入门 行业动态 更新时间:2024-10-27 21:18:20
本文介绍了轻微的加载延迟与铬扩展弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

出于某种原因,当我在加载弹出窗口之前点击我的扩展程序时,我的延迟非常小。

弹出窗口前显示1-2秒的呃逆,而我所有的其他扩展立即显示弹出的HTML。

正如你在上面看到的,当我点击弹出窗口时,甚至会出现加载光标动画,而其他扩展程序从来不会发生。

这是我的popup html:

<!doctype html> < html> < head> < script type =text / javascriptsrc =popup.js>< / script> < title>添加要阻止的网站< / title> < / head> < body> < form id =addWebsiteForm> 网站地址:< input type =textid =websiteAddress>< br> < input type =submitvalue =添加网站> < / form> < / body> < / html>

我的popup.js

var addWebsiteForm; document.addEventListener('DOMContentLoaded',function(){ addWebsiteForm = document.getElementById(addWebsiteForm); addWebsiteForm.addEventListener('submit',addWebsite); }); 函数addWebsite(event){ event.preventDefault(); var websiteAddressInput = document.getElementById(websiteAddress); var websiteAddress = websiteAddressInput.value; var storedWebsites; chrome.storage.local.get('websites',function(objects){ if(!objects.websites){ storedWebsites = []; } else { storedWebsites = objects.websites; } storedWebsites.push({'address':websiteAddress}); chrome.storage .local.set({'websites':storedWebsites}); addWebsiteForm.reset(); websiteAddressInput.focus(); }); }

我的清单:

{manifest_version:2, name:Quizlet Extension,description:Go通过你的flashcards在移动到网站之前,version:1.0, options_page:options.html, browser_action :{default_icon:icon.png,default_popup:popup.html}, permissions:[存储}

任何想法?

解决方案

我认为您可以尝试将背景 params添加到清单:

{ ... background:{page:background.html,persistent:true }, ... }

当然,需要在扩展文件夹中添加一个简单的html文件:

<!DOCTYPE html> < html> < head> < meta charset =utf-8/> < / head> < body> < / body> < / html>

现在打开Chrome扩展程序会很快没有不延迟 $ b

后台页面将始终运行 ,它总是用于显示通知。所以我们可以利用这个功能,不需要重新打开延迟,这是延迟的主要原因。

For some reason, I have a very small delay when I click my extension before the popup is loaded.

It's a 1-2 second hiccup before the popup displays, while all my other extensions display the popup html immediately.

As you can see above, there is even the loading cursor animation when I click the popup, which never happens for the other extensions.

Here is my popup html:

<!doctype html> <html> <head> <script type="text/javascript" src="popup.js"></script> <title>Add a website to block</title> </head> <body> <form id="addWebsiteForm"> Website Address: <input type="text" id="websiteAddress"><br> <input type="submit" value="Add Website"> </form> </body> </html>

My popup.js

var addWebsiteForm; document.addEventListener('DOMContentLoaded', function(){ addWebsiteForm = document.getElementById("addWebsiteForm"); addWebsiteForm.addEventListener('submit', addWebsite); }); function addWebsite(event) { event.preventDefault(); var websiteAddressInput = document.getElementById("websiteAddress"); var websiteAddress = websiteAddressInput.value; var storedWebsites; chrome.storage.local.get('websites', function(objects) { if (!objects.websites) { storedWebsites = []; } else { storedWebsites = objects.websites; } storedWebsites.push({'address':websiteAddress}); chrome.storage.local.set({'websites':storedWebsites}); addWebsiteForm.reset(); websiteAddressInput.focus(); }); }

And my manifest:

{ "manifest_version": 2, "name": "Quizlet Extension", "description": "Go through your flashcards before moving onto a website", "version": "1.0", "options_page":"options.html", "browser_action": { "default_icon": "icon.png", "default_popup": "popup.html" }, "permissions": [ "storage" ] }

Any ideas?

解决方案

I think you can try to add the background params to the manifest :

{ ... "background": { "page": "background.html", "persistent": true }, ... }

Of course, need add a simple html file to the extension folder :

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> </head> <body> </body> </html>

Now open the Chrome Extension will be quickly without no delay.

The background page will be run all the time, it is always used to show notification.So we can make use of this feature, need't reopen the Extension which is the main reason of delay

更多推荐

轻微的加载延迟与铬扩展弹出

本文发布于:2023-10-06 19:47:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467646.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出   轻微   加载

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!