-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
40 lines (35 loc) · 1.27 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
var profilerUrl = [];
var currentTab;
chrome.tabs.onActivated.addListener(function (tab) {
currentTab = tab.tabId;
updateIcon();
});
chrome.browserAction.onClicked.addListener(function() {
if (profilerUrl.hasOwnProperty(currentTab) && profilerUrl[currentTab] !== null) {
chrome.tabs.create({url: profilerUrl[currentTab]});
}
});
chrome.webRequest.onHeadersReceived.addListener(
function(details) {
if (details.type === 'main_frame') {
profilerUrl[currentTab] = null;
for (var header of details.responseHeaders) {
if (header.name.toLowerCase() === 'x-debug-token-link') {
profilerUrl[currentTab] = header.value;
}
}
updateIcon();
}
},
{urls: ["<all_urls>"]},
['responseHeaders']
);
updateIcon = function() {
if (profilerUrl.hasOwnProperty(currentTab) && profilerUrl[currentTab] !== null) {
chrome.browserAction.setIcon({path: 'icon-38.png'});
chrome.browserAction.setTitle({title: 'Symfony Profiler information available'});
} else {
chrome.browserAction.setIcon({path: 'icon-disabled-38.png'});
chrome.browserAction.setTitle({title: 'No Symfony Profiler information found for this page'});
}
};