-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
32 lines (27 loc) · 1.13 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
// Background Service Worker (Manifest V3)
chrome.runtime.onInstalled.addListener(() => {
console.log('Lovable AI Debug Helper extension installed.');
// You could set default settings here using chrome.storage.local.set()
});
// Listen for messages if needed (e.g., from content scripts or panel)
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log("Background received message:", message);
// Example: Handle a request that needs background processing
if (message.action === "performBackgroundTask") {
// Do something in the background
sendResponse({ status: "Background task completed" });
}
return true; // Indicates you wish to send a response asynchronously
});
// Keep alive logic (basic example, might need refinement for complex tasks)
let keepAliveInterval;
chrome.runtime.onConnect.addListener(port => {
if (port.name === 'keepAlive') {
keepAliveInterval = setInterval(() => {
port.postMessage({ message: 'ping' });
}, 25 * 1000); // Ping every 25 seconds
port.onDisconnect.addListener(() => {
clearInterval(keepAliveInterval);
});
}
});