轻微的加载延迟与铬扩展弹出 [英] Slight loading delay with chrome extension popup

查看:121
本文介绍了轻微的加载延迟与铬扩展弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

弹出窗口前显示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

这篇关于轻微的加载延迟与铬扩展弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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