【发布时间】:2011-05-10 02:22:32
【问题描述】:
我正在为 Chrome 编写一个扩展程序,以显示用户访问次数最多的 3 个站点。 (是的,我知道“新标签”页面已经这样做了)但是,每当我尝试查询用户历史记录时,似乎整个脚本都关闭了。
我的清单文件确实包含:
{
"name": "Most Visited Sites Test",
"description": "Show your most visited sites",
"version": "1.0",
"background_page": "background.html",
"app": {
"launch": {
"web_url": "http://localhost/*"
}
},
"permissions": [
"tabs",
"history",
"unlimitedStorage",
"notifications"
],
"icons": {"128": "icon.png" },
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentscript.js"]
}
]
}
所以我相信这应该让我的背景页面能够使用历史记录。但是,我的背景页面包含:
function onRequest(request, sender, sendResponse)
{
alert("Call 1");
var oneWeekAgo = //Code for getting last weeks date;
chrome.history.search({
'text': '',
'startTime': oneWeekAgo
},
function(historyItems)
{
// Do stuff...
});
alert("Call 2");
};
请求是从我的 contentscript.js 发出的
chrome.extension.sendRequest("foo");
运行时,会显示“Call 1”,但不会对历史记录进行任何操作,并且永远不会显示“Call 2”。这可能是什么原因造成的?如果这是一个简单的问题,我深表歉意,但这是我第一次尝试合法的 Chrome 扩展程序。
【问题讨论】:
标签: javascript google-chrome-extension browser-history