25 lines
960 B
JavaScript
25 lines
960 B
JavaScript
console.log("background.js loaded");
|
|
|
|
// Listen for messages from the devtools panel
|
|
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
// You could add a check to see if the message is from the devtools panel.
|
|
if (message.type === "GET_CONTEXT_STACK") {
|
|
// Forward the message to the content script running in the active tab.
|
|
browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
|
|
if (tabs.length) {
|
|
browser.tabs.sendMessage(tabs[0].id, message).then(sendResponse);
|
|
}
|
|
});
|
|
// Return true to indicate you wish to send a response asynchronously
|
|
return true;
|
|
} else if (message.type === "UPDATE_CONTEXT_VALUE") {
|
|
// Forward update messages similarly
|
|
browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
|
|
if (tabs.length) {
|
|
browser.tabs.sendMessage(tabs[0].id, message).then(sendResponse);
|
|
}
|
|
});
|
|
return true;
|
|
}
|
|
});
|