javascript - runtime.onMessage sender parameter does not contain the tab info -


i have browser action sends message

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);     } } 

and listener on 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 problem im having need tab current selected tab without having send message. read sender should have tab object doesnt. wondering if doing wrong here.

well, property sender implies it has information sent message, not received it.

since sender background page, wrong result.

messages can of (json-compatible) format - can object many keys like; should include tab id in message:

function tab_message(tab_id, message) {     if (message) {         message.tabid = tab_id;         // message becomes {tabid: ..., ...}         chrome.tabs.sendmessage(tab_id, message);     } } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -