我正在创建一个跟踪特定网址的扩展程序,并显示访问该网址时的日期,然后将其保存到文本文件中。它只在我运行页面和脚本时有效,但是当它添加到chrome时它什么都不做。
的manifest.json
{
"name": "Login Tracker",
"version": "0.1",
"manifest_version": 2,
"description": "A Chrome Extension that records the time that you log in",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Login Tracker"
},
"permissions": ["tabs",
"background", "browsingData", "contextMenus", "downloads"
],
"background": {
"scripts": ["loginPage.js", "func.js"]
}
}
loginPage.html
<html>
<head>
<script type="text/javascript" src="func.js">
</script>
</head>
<body>
<h1>Login Tracker</h1>
<p id=demo></p>
<button type="button" onclick="myFunction()">Login</button>
</body>
</html>
func.js
function myFunction() {
var d = new Date();
document.getElementById("demo").innerHTML = d;
var textToSave = d;
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:attachment/text,' +
encodeURI(textToSave);
hiddenElement.target = '_blank';
hiddenElement.download = d;
hiddenElement.click();
}
loginPage.js
chrome.browserAction.onClicked.addListener(function (activeTab) {
var newURL = "loginPage.html";
chrome.tabs.create({
url: newURL
});
});
知道为什么即使只显示日期也没有做任何事情?它在我在本地查看时工作,但在添加到chrome时它没有做任何事情。任何帮助将不胜感激。