-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
49 lines (41 loc) · 1.46 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Regex-pattern to check URLs against.
// It matches URLs like: http[s]://[...]stackoverflow.com[...]
// var urlRegex = /^https?:\/\/(?:[^./?#]+\.)?stackoverflow\.com/;
// A function to use as callback
function doStuffWithDom(domContent) {
console.log('I received the following DOM content:\n' + domContent);
}
// When the browser-action button is clicked...
chrome.browserAction.onClicked.addListener(function (tab) {
console.log("TAB", tab);
// ...check the URL of the active tab against our pattern and...
if (tab.url.includes("amazon.ca")) {
// ...if it matches, send a message specifying a callback too
chrome.tabs.sendMessage(tab.id, {text: 'report_back'}, doStuffWithDom);
}
});
// chrome.runtime.onMessage.addListener(
// function(request, sender, sendResponse) {
// console.log("MESSAGE RECIEVED: ", request)
// if( request.message === "all_urls_fetched" ) {
// console.log("MESSAGE RECIEVED: ", request)
// }
// }
// );
chrome.runtime.onConnect.addListener(port => {
port.onMessage.addListener(msg => {
console.log("MSG recieved: ", msg)
// Handle message however you want
}
);
})
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(request, sender);
console.log("RECIEVING MESSAGE in POPUP");
if( request.message === "get_product" ) {
console.log(request)
// Handle the message
}
}
);