-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
23 lines (21 loc) · 798 Bytes
/
background.js
File metadata and controls
23 lines (21 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Listen for tab close event
chrome.tabs.onRemoved.addListener((tabId) => {
// Send request to backend to clear memory for this tab
fetch(`${window.API_BASE_URL}/clear_memory`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ tab_id: tabId })
}).catch((err) => console.error("Error clearing memory:", err));
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "get_tab_id") {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0) {
sendResponse({ tabId: tabs[0].id });
} else {
sendResponse({ tabId: null });
}
});
return true;
}
});