-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathbackground_script.js
More file actions
19 lines (17 loc) · 833 Bytes
/
background_script.js
File metadata and controls
19 lines (17 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// We want to broadcast a message to this extension's content scripts in every tab when a key
// mapping changes. However, the chrome.tabs API is only available to background scripts.
chrome.runtime.onMessage.addListener(async (request) => {
console.log("Background page received message.", request);
const onError = (error) => {
// The error "could not establish connection. Receiving end does not exist" happens when the
// tabs being queried are not Google Sheets pages and do not have the SheetKeys content scripts
// loaded. This is expected.
console.log("Error sending message to tabs:", error);
};
if (request == "keyMappingChange") {
const tabs = await chrome.tabs.query({});
for (const tab of Array.from(tabs)) {
chrome.tabs.sendMessage(tab.id, request).catch(onError);
}
}
});