-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (31 loc) · 1.21 KB
/
background.js
File metadata and controls
38 lines (31 loc) · 1.21 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
// Background service worker for UX Analyzer extension
console.log('Background script starting...');
// Handle extension icon clicks
chrome.action.onClicked.addListener((tab) => {
console.log('Extension icon clicked for tab:', tab.id);
// Simple injection without async/await for better compatibility
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['content.js']
}, () => {
if (chrome.runtime.lastError) {
console.error('Script injection failed:', chrome.runtime.lastError);
return;
}
console.log('Content script injected successfully');
// Send message to toggle overlay
chrome.tabs.sendMessage(tab.id, { action: 'toggleOverlay' }, (response) => {
if (chrome.runtime.lastError) {
console.error('Message sending failed:', chrome.runtime.lastError);
} else {
console.log('Message sent successfully');
}
});
});
});
// Handle messages from content scripts
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log('Received message:', message);
sendResponse({ success: true });
});
console.log('Background script loaded and listeners attached');