-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
21 lines (20 loc) · 864 Bytes
/
Copy pathbackground.js
File metadata and controls
21 lines (20 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// background.js
// Listen for URL changes in the tabs
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// Check if the status is 'complete' to ensure the page has fully loaded
if (changeInfo.status === 'complete') {
chrome.tabs.get(tabId, function (tab) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
} else {
chrome.tabs.sendMessage(tabId, { action: 'updateContent', url: tab.url }, function (response) {
if (chrome.runtime.lastError) {
console.log('Error sending message:', chrome.runtime.lastError.message);
} else if (response) {
console.log('Message sent successfully');
}
});
}
});
}
});