Currently, I am in the process of developing my initial chrome extension and focusing on establishing message passing and background.js functionality. However, it seems like my background.js file is not being triggered or receiving any messages. I am seeking assistance in identifying what I might be doing incorrectly. Below is a simplified example of my setup:
manifest.json
{
"manifest_version": 2,
"name": "RAData",
"version": "0.1",
"background": {
"scripts": ["background.js"] },
"content_scripts": [{
"matches": [
"<all_urls>"],
"js": ["content.js"] }]
}
content.js
chrome.runtime.sendMessage("message from content");
console.log("content.js loaded");
background.js
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
console.log("message received");
});
console.log("background.js loaded");
In theory, whenever a page is loaded, content.js should execute, display "content.js loaded" in the console, and then activate background.js with the message. Background.js should then display "message received" and "background.js loaded" in the console.
However, in reality, the console only shows "content.js loaded", indicating that none of the code in background.js is being run.