-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
49 lines (47 loc) · 1.69 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// ```background.js
// Listener for extension icon click action
chrome.action.onClicked.addListener((tab) => {
if (tab && tab.id) {
chrome.tabs.query(
{ active: true, currentWindow: true },
function (tabs) {
if (tabs[0]) {
chrome.tabs.sendMessage(
tabs[0].id,
{ action: "activate" },
function (response) {
if (chrome.runtime.lastError) {
console.error(
`Error sending message: ${chrome.runtime.lastError.message}`,
);
} else {
console.log("Message sent successfully");
}
},
);
}
},
);
} else {
console.error("Error: invalid tab or tab ID not available.");
}
});
// Listener for extension installation event
chrome.runtime.onInstalled.addListener((details) => {
switch (details.reason) {
case chrome.runtime.OnInstalledReason.INSTALL:
console.log("PrometheusWorkana extension installed.");
break;
case chrome.runtime.OnInstalledReason.UPDATE:
console.log("PrometheusWorkana extension updated.");
break;
case chrome.runtime.OnInstalledReason.CHROME_UPDATE:
console.log(
"Chrome updated, please check extension compatibility.",
);
break;
default:
console.log("Unknown installation event:", details);
break;
}
});