Merge pull request #16 from biancadanforth/initial-data-capture

Simplified data capture to storage API. Fixes #7.
This commit is contained in:
Jonathan Kingston 2017-05-25 10:25:08 +01:00 коммит произвёл GitHub
Родитель 0ac4ce36a2 dcf51ddf73
Коммит b16d959698
3 изменённых файлов: 52 добавлений и 2 удалений

Просмотреть файл

@ -3,8 +3,9 @@
// When the user clicks browserAction icon in toolbar, execute runLightbeam function
browser.browserAction.onClicked.addListener(runLightbeam);
async function runLightbeam() {
capture.init();
async function runLightbeam() {
// Checks to see if Lightbeam is already open. Returns true if it is, false if not.
async function isOpen() {
const tabs = await browser.tabs.query({});

46
capture.js Normal file
Просмотреть файл

@ -0,0 +1,46 @@
const capture = {
init() {
this.addListeners();
},
addListeners() {
// listen for each HTTP response
browser.webRequest.onResponseStarted.addListener(this.sendThirdParty, {urls: ['<all_urls>']}
);
// listen for tab updates
browser.tabs.onUpdated.addListener(this.sendFirstParty);
},
// capture third party requests
async sendThirdParty(response) {
const tab = await browser.tabs.get(response.tabId);
let tabUrl = new URL(tab.url);
let targetUrl = new URL(response.url);
let originUrl = new URL(response.originUrl);
if (targetUrl !== tabUrl) {
const thirdPartyData = {
document: tabUrl.hostname,
target: targetUrl.hostname,
origin: originUrl.hostname,
requestTime: response.timeStamp
};
console.log('storage.thirdPartyRequest:', tabUrl, thirdPartyData);
}
},
// capture first party requests
sendFirstParty(tabId, changeInfo, tab) {
const tabUrl = new URL(tab.url);
// ignore about:* pages and non-visible tabs
if (tab.status === 'complete'
&& tabUrl.protocol !== 'about:'
&& tabId !== browser.tabs.TAB_ID_NONE)
{
const firstPartyData = {
faviconUrl: tab.favIconUrl,
};
console.log('storage.firstPartyRequest:', tabUrl.hostname, firstPartyData);
}
}
};

Просмотреть файл

@ -24,6 +24,9 @@
},
"background": {
"scripts": ["background.js"]
"scripts": [
"capture.js",
"background.js"
]
}
}