[英]Slight loading delay with chrome extension popup
由于某些原因,在加载弹出窗口之前单击扩展名时,我的延迟很小。
在弹出窗口显示之前是1-2秒的打ic,而我所有其他扩展都立即显示弹出html。
正如您在上面看到的,当我单击弹出窗口时,甚至还有正在加载的光标动画,而其他扩展程序则从来没有发生过。
这是我的弹出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>
我的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();
});
}
而我的清单:
{
"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"
]
}
有任何想法吗?
我认为您可以尝试将background
参数添加到manifest
:
{
...
"background": {
"page": "background.html",
"persistent": true
},
...
}
当然,需要在扩展文件夹中添加一个简单的html文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
</body>
</html>
现在打开Chrome扩展程序将很快而no delay
。
该background page
将运行all the time
,它总是用来显示notification.So我们可以利用这个特性,need't重新打开该扩展是延迟的主要原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.