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

275
Views
background to foreground chrome.runtime.onMessage() failing

Check the google chrome extension code bellow.Here i am simply trying to send a basic string message from background to foreground but i am getting error in tab console: Error in event handler: TypeError: Error in invocation of tabs.sendMessage(integer tabId, any message, optional object options, optional function callback): No matching signature. Whats wrong i am doing here any idea?

manifest.json:

{
    "name": "obj ext",
    "description": "my ext",
    "version": "0.1.0",
    "manifest_version": 2,
    "icons": {
        "16": "./obj-16x16.png",
        "32": "./obj-32x32.png",
        "48": "./obj-48x48.png",
        "128": "./obj-128x128.png"
    },
    "background":{
        "scripts":["./background.js"]
    },
    "options_page":"./options.html",
    "browser_action":{
        "default_popup": "popup.html"
    },
    "permissions":[
        "tabs",
        "https://www.google.com/"
    ]
}

background.js:

chrome.tabs.onActivated.addListener(tab => {
   

    console.log(tab.tabId);
    chrome.tabs.sendMessage(
        {tabId: tab.tabId},
        {message: 'Hello'}
      );

 
});

foreground.js

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    
    console.log(message);
  });
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You passed an object with attribute tabId. It should be a number type variable.

Correct use case:

// other code
chrome.tabs.sendMessage(
        tab.tabId,
        {message: 'Hello'}
);
// other code

API doc:

chrome.tabs.sendMessage(
  tabId: number, // Pay attention here
  message: any,
  options?: object,
  responseCallback?: function,
)
about 4 years ago · Santiago Gelvez Report
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!