-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
43 lines (38 loc) · 1.35 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
let transitions = {};
// Send message to content to inject DOM listeners
function notifyInjectDomListener(tabId) {
chrome.tabs.sendMessage(tabId, {type: 'injectDomListener'});
}
// Add listener for begin of page load to
// capture URL and reason for URL change.
chrome.webNavigation.onCommitted.addListener(function(details) {
if (details.frameId === 0) {
console.log(details.transitionType);
if (details.transitionType === 'typed' || details.transitionType === 'reload') {
transitions[details.tabId] = {type: 'goto', url: details.url};
} else {
transitions[details.tabId] = {type: 'urlChange', url: details.url};
}
}
});
// On navigation completed, send message to content to capture
// step
chrome.webNavigation.onCompleted.addListener(function(details) {
// Only check for requests of the actual tab
if (details.frameId == 0) {
if (transitions[details.tabId]) {
chrome.tabs.sendMessage(details.tabId, transitions[details.tabId]);
transitions[details.tabId] = undefined;
}
notifyInjectDomListener(details.tabId);
}
});
chrome.contextMenus.removeAll();
chrome.contextMenus.create({
id: "jmon_check_element_content",
title: "Check element content",
contexts: ["all"]
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
chrome.tabs.sendMessage(tab.id, {type: "checkContextMenuContent"});
})