Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Cannot get Chrome extension background.js to communicate with content.js

Trying to send a message from background.js to content.js returns Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

I've tried:

background.js

chrome.tabs.onRemoved.addListener((tabId, removeInfo) => {
  chrome.tabs.sendMessage(tabId, "some-random-message")
})

content.js

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  alert(message)
  sendResponse("Successfully received message.")
})

Is this happening because I'm trying to send a message to my content script after that tab has been closed? If so, is there any way to still access the document in the content script after or while the tab is closing?

To add more info, I also did try using chrome.tabs.onCreated... instead of onRemoved but with no avail.

EDIT: Adding my manifest.json file.

{
    "manifest_version": 3,
    "name": "Some Extension Name",
    "version": "0.0.1",

    "action": {
        "default_popup": "popup.html",
        "default_title": "Some Extension Name"
    },

    "content_scripts": [
        {
            "matches": ["<all_urls>"],
            "js": ["./content.js"]
        }
    ],

    "background": {
        "service_worker": "./background.js"
    },
    
    "permissions": ["cookies", "tabs", "storage"]
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!