0

ERROR: "chromeWindow.state" is undefined here

Can you put me in the right direction?

chrome.runtime.onMessage.addListener(function(message,sender,sendResponse) 
{
  chrome.windows.get(sender.tab.windowId, function(chromeWindow) {
    // chromeWindow is DEFINED HERE
    console.log('sending to contentscript :', chromeWindow.state);
  });
  // chromeWindow.state is UNDEFINED
  sendResponse(**chromeWindow.state**);
});
Fabian N.
  • 3,807
  • 2
  • 23
  • 46
Medy
  • 55
  • 1
  • 6
  • It looks like the scope is not right. https://www.pluralsight.com/guides/javascript-callbacks-variable-scope-problem – Iskandar Reza Aug 29 '18 at 20:28
  • 1
    Function parameters exist only within the scope of the function to which they are passed. You should read more about how [functions in JavaScript work](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions). – aaplmath Aug 29 '18 at 20:28

1 Answers1

0
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse) 
{
  chrome.windows.get(sender.tab.windowId, function(chromeWindow) {
      sendResponse(chromeWindow.state);
  });
});
  • this is how I did it at first ... maybe there is another issue ...will add full code. – Medy Aug 29 '18 at 20:59
  • ok the duplicate topic pointed me in the right direction... it was a synching issue. I added : return true; https://developer.chrome.com/apps/messaging – Medy Aug 29 '18 at 21:17