-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
48 lines (42 loc) · 1.75 KB
/
background.js
File metadata and controls
48 lines (42 loc) · 1.75 KB
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
chrome.runtime.onInstalled.addListener(function () {
console.log("Subsleuth extension installed or updated.");
});
chrome.action.onClicked.addListener(function (tab) {
const currentUrl = tab.url;
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, { message: "checkUrl", url: currentUrl });
});
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.message === "result") {
const result = request.result;
// Display a notification with the result
chrome.notifications.create({
type: "basic",
iconUrl: "icon.png",
title: "Subsleuth",
message: result.isMalicious ? "This website is malicious!" : "This website is safe.",
});
}
});
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.action === 'highlightDealOfTheDay') {
console.log('Received message from popup script. Forwarding to content script...');
// Send a message to the content script to highlight "deal of the day"
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
var activeTab = tabs[0];
// Use chrome.scripting.executeScript instead
chrome.scripting.executeScript({
target: { tabId: activeTab.id, allFrames: true },
files: ['content.js'],
}).then(() => {
// Send message only after successful script injection
chrome.tabs.sendMessage(activeTab.id, { action: 'highlightDealOfTheDay' });
}).catch(error => {
// Handle potential errors during script injection
console.error('Error injecting script:', error);
});
});
}
});