我在这里看到很多答案,但没有人是我在找什么。 我想从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我从来没有得到,我不知道为什么。请帮助..
感谢..
UPDATE
那是缺失的部分(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);
});
我得到的消息:遗漏的类型错误:无法读取的不确定 – avishayhajbi
财产“captureVisibleTab”你调用captureVisibleTab内容脚本? – Chickenrice
你对我非常感谢,我修好了! – avishayhajbi