1

Here's the code to the popup.jsx file and the background index.js file. For starters, I'm just working with a simple alert. the way I've gone with the working is that the background makes note of any new tabs using chrome.tabs.onCreated() and sends a message to the popup once so, the issue I feel I'm facing is that the popup isnt receiving the message sent by the background file. please help out if you can, this is the link to the Github repo.https://github.com/Brihadeeshrk/extension popup.jsx

chrome.runtime.onMessage.addListener((req) => {
    console.log("message: "+req.message)
    if(req.type === 'newTabCreated') {
      alert("new tab")
    }
    return true
  })

background.js

chrome.tabs.onCreated.addListener(function() {
    console.log('new tab created')
    chrome.runtime.sendMessage({
        type: "newTabCreated",
        message: "new tab created121"
    }, function() {
        console.log("message sent")
    })
})
Veeresh Devireddy
  • 1,057
  • 12
  • 24
  • Are you saying that the PopUp doesn't receive message when it isn't open? Or are you asking something else? – noninertialframe Oct 08 '21 at 20:37
  • The popup specified in `browser_action` or `action` doesn't run when it's not shown so naturally it can't receive messages. You can create a new window and show the popup there or you can add the popup as a DOM element on the page, [example](https://stackoverflow.com/a/25100953). – wOxxOm Oct 09 '21 at 05:41
  • Let me explain the working of the above mentioned app, it's supposed to open the extension as soon as the user opens a new tab. Now, the issue i've been facing is that, the popup.jsx file isn't receiving the message sent by the background.js file. I've console.logged the background message and it does appear on the console as soon as a new tab is opened. I feel i'm going wrong in 1 of 2 places: 1. message isnt being received by popup.jsx 2. something wrong with my popup logic – Brihadeesh R K Oct 10 '21 at 14:21

0 Answers0