I've implemented a browser action that triggers a message to be sent.
chrome.browserAction.onClicked.addListener(function(tab) {
var message = {
'message': 'overlay-intent'
};
tab_message(tab.id, message);
});
function tab_message(tab_id, message) {
if (message) {
chrome.tabs.sendMessage(tab_id, message);
}
}
Additionally, I have a listener set up on my content script.
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
var domain = window.location.host;
ext_id = sender.id;
if (request.message === 'overlay-intent') {
if (is_modal_open()) {
return close_modal();
}
if (csp_blacklist.indexOf(domain) > -1 ) {
return create_tab();
}
var src = build_source(sender.tab.id);
open_modal(src);
}
});
The issue I'm facing is obtaining the current selected tab without sending an additional message. Despite reading that the sender object should contain a tab property, it doesn't seem to appear for me. Any insights or suggestions are appreciated!