I am building a Chrome extension and am trying to send a message to my event background.js page from inside of chrome.tabs.captureVisibleTab()
. For some reason the message will not send to my content script...
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var responseObj = new Object();
if(request.screenshotRequest == true){
chrome.tabs.captureVisibleTab({ format: "png"}, function(dataUrl){
responseObj.screenshotRequest = dataUrl;
alert(sendResponse);
sendResponse(responseObj);
});
}
});
My manifest.json
allows for the correct permissions to allow this message passing to happen. When I try and pass messages using sendResponse()
outside of the chrome.tabs.captureVisibleTab()
the message passes correctly and I can access it from the content script. Any idea why this isn't passing?
UPDATE: alert(sendResponse);
proves that chrome.tabs.captureVisibleTabs()
has access to sendResponse
because the object is correctly displayed in the alert message.