0

I'm new to javascript so I apologies if this is obvious and everyone knows.

I'm using Message Passing to intruct the background.js of my Chrome Extension to perform an action when you press a button in the extensions popup.js

popup.js:

getCurrentTab(function(tab) {
    chrome.runtime.sendMessage(
        {type: 'status', tabId: tab.id },
        function(response) {
            console.log(response.message)
        }
    )
})

Background.js:

chrome.runtime.onMessage.addListener(
  function(message, sender, callback) {
    console.log("Received message" + message + ", " + sender + "," + callback)
    alert('received')
    callback({message: message.type});
})

I've already learned that i need to "Inspect" my popup window for it's console (where I can see the response being printed).

I can see the page is alerting, and I can see the response in my popups console. But the main pages console isn't being filled (with message starting "Received message").

Can someone help a poor js beginner out?

Graeme
  • 25,714
  • 24
  • 124
  • 186
  • I think this answer may be useful to you: https://stackoverflow.com/a/17293612/5177045 – amedina Aug 18 '20 at 21:40
  • FYI: There is no need for message passing between popup page and background script as they both run in the _same context_. A popup page may have direct access to background script's functionality via [`getBackgroundPage`](https://developer.chrome.com/extensions/runtime#method-getBackgroundPage) method – hindmost Aug 19 '20 at 10:45

1 Answers1

0

@Amedina has rightly suggested my answer is here:

https://stackoverflow.com/a/17293612/726954

I should be using the extension page to access my background.js console

Graeme
  • 25,714
  • 24
  • 124
  • 186