-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
26 lines (22 loc) · 1.11 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
// background page has two options: sendToActiveTab and getCurrentUrl
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
// forwards requests to and returns the resulting response from the active tab
// listens for message of the form {message: "sendToActiveTab", arg: <message-to-send-active tab>}
if (request.message == "sendToActiveTab") {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, request.arg, function(response) {
sendResponse({courseId: response.courseId});
});
});
return true; // keep message channel open to be able to call sendResponse asynchronously in a callback
}
// enables content scripts to know their own environment's URL
else if (request == "getCurrentUrl") {
sendResponse({url: sender.tab.url});
}
}
);
// message flow:
// kiwi needs id -> messages "getCourseId" to same page's content script, receiving courseId
// vendor pages listen for above messages