【发布时间】:2015-06-13 07:39:46
【问题描述】:
我在这里看到了很多答案,但没有一个是我要找的。 我想从 chrome 扩展中截取屏幕截图,只为我第一次看到的屏幕而不滚动页面。 并“提醒”创建的文件 base64 路径。
我拥有所有正确的权限:
"permissions": [
"activeTab",
"tabs" ,
"storage",
"unlimitedStorage",
"browsingData",
"notifications",
"http://*/*",
"https://*/*",
"file://*/*",
"background" // added after i got the answer
],
"background": { // added after i got the answer
"scripts": [
"js/background.js"
]
},
在我的 manifest.json 中
我也有代码:
$(document).ready(function() {
alert("1");
chrome.tabs.captureVisibleTab(null, {}, function (image) {
alert("2");
});
});
我一直得到 1,但我从来没有得到 2,我不知道为什么。请帮忙..
谢谢..
更新
这是缺少的部分(background.js)
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
chrome.tabs.captureVisibleTab(
null,
{},
function(dataUrl){
sendResponse({imgSrc:dataUrl});
}); //remember that captureVisibleTab() is a statement
return true;
}
);
然后:
chrome.tabs.captureVisibleTab(null, {}, function (image) {
// alert("2");
alert(response.imgSrc);
});
【问题讨论】:
标签: javascript google-chrome google-chrome-extension