I'm making a simple chrome extension and I ran into this error. I've tried looking around to and the most I've found is that I'm likely running into an error with the parameters of the chrome.tabs.sendMessage. I tried console.log(tab[0].id) and it is in fact an integer. The docs say the message param can be a string and the other two params are optional and not needed in this context.
Uncaught (in promise) TypeError: Error in invocation of tabs.sendMessage(integer tabId, any
message, optional object options, optional function callback): No matching signature.
at background.js:18:21
Here's my code:
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
"title": 'Help With PIM',
"id": 'pimhelper',
"contexts": ['all'],
});
});
chrome.contextMenus.onClicked.addListener(async (info) => { if (info.menuItemId === "pimhelper") {
let queryOptions = { active: true, currentWindow: true };
let tab = await chrome.tabs.query(queryOptions);
chrome.tabs.sendMessage((tab[0].id, '"message"'))
}
});
Possible ideas:
There might be something wrong with the message param and I read something about data serialization on the docs. Not sure how to use the JSON parse or stringify methods to solve this however.
I apologize if this is some noob mistake. I am entirely new to creating chrome extensions.