Files
BotExt/app/sw.js
T
2023-09-05 22:48:20 +08:00

25 lines
739 B
JavaScript

function injectedFunction(color) {
document.body.style.backgroundColor = color;
}
chrome.runtime.onMessage.addListener(async ({ name, options }) => {
if (name === 'addRecord') {
console.log('Hello World!');
// get active tab
// const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
// chrome.scripting.executeScript({
// target: { tabId: tab.id },
// func: injectedFunction,
// args: ["orange"],
// });
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const response = await chrome.tabs.sendMessage(tab.id, { greeting: "hello" });
// do something with response here, not outside the function
console.log(response);
}
});