我正在尝试创建一个弹出窗口,它将显示可视选项卡为一个小图像。从ImgSrc ()函数返回的chrome.tabs.captureVisibleTab是“未定义的”。我试过从不同的地方运行这个。我可以验证从tabs.Query()返回的选项卡不是空的,所以tabs.id不是空的。
我做得不对吗?
这是我的清单,popup.html和popup.js文件:
{
"manifest_version": 2,
"name": "SuperFave",
"description": "Saves favorites demo",
"version": "1.0",
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"<all_urls>"
]
}
popup.html:
<html>
<head>
<script type="text/javascript" src="jquery-1.10.2.min.js">
</script>
<script type="text/javascript" src="popup.js">
</script>
</head>
<body>
</body>
</html>
popup.js:
$(document).ready( function () {
chrome.tabs.query( {
// gets the window the user can currently see
active: true,
currentWindow: true
},
function (tabs) {
chrome.tabs.captureVisibleTab(
tabs[0].id,
function (src) {
// displays a link to the image. Can be replaced by an alert() to
// verify the result is 'undefined'
$('body').append("<a href='" + src + "'>" + tabs[0].url + "</a>");
}
);
}
);
});
发布于 2013-08-29 01:54:00
captureVisibleTab只在窗口中的当前活动选项卡上工作。因此,我需要传入窗口id,而不是选项卡id。
popup.js必须是:
$(document).ready( function () {
chrome.tabs.query( {
// gets the window the user can currently see
active: true,
currentWindow: true
},
function (tabs) {
chrome.tabs.captureVisibleTab(
chrome.windows.WINDOW_ID_CURRENT,
function (src) {
// displays a link to the image. Can be replaced by an alert() to
// verify the result is 'undefined'
$('body').append("<a href='" + src + "'>" + tabs[0].url + "</a>");
}
);
}
);
});
https://stackoverflow.com/questions/18500568
复制相似问题