Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refining onBeforeRequest handler to minimize the number of requests without corresponding page url. #138

Merged
merged 10 commits into from Aug 2, 2018
Refactor logic.
  • Loading branch information
jsignanini committed Jul 24, 2018
commit c90329d1ade9ee59de5402b67ea06098dc6dbbef
@@ -335,27 +335,25 @@ class EventHandlers {
return { cancel: false };
}

if (details.type === 'main_frame') {
if (!tabInfo.getTabInfo(tab_id)) {
if (!tabInfo.getTabInfo(tab_id)) {
log(`tabInfo not found for tab ${tab_id}, initializing...`);

// create new tabInfo entry
if (details.type === 'main_frame') {
tabInfo.create(tab_id, details.url);
} else {
tabInfo.setTabInfo(tab_id, 'url', details.url);
tabInfo.create(tab_id);
}
}

if (!tabInfo.getTabInfo(tab_id)) {
// get tab data from browser and update the new tabInfo entry
utils.getTab(tab_id, (tab) => {
if (!tabInfo.getTabInfo(tab_id)) {
tabInfo.create(tab_id, tab.url);
} else {
const ti = tabInfo.getTabInfo(tab_id);
if (!ti) { return; }
if (ti.partialScan) {
tabInfo.setTabInfo(tab_id, 'url', tab.url);
}
tabInfo.setTabInfo(tab_id, 'incognito', tab.incognito);
},
(error) => {
log('TAB CANNOT BE QUERIED', error, tabInfo.getTabInfo(tab_id));
}
);
});
}

if (!this._checkRedirect(details.type, request_id)) {
@@ -382,6 +380,8 @@ class EventHandlers {
this._throttleButtonUpdate();
return { cancel: false };
}
// add the bugId to the details object. This can then be read by other handlers on this pipeline.
details.ghosteryBug = bug_id;

/* ** SMART BLOCKING - Breakage ** */
// allow first party trackers
@@ -7,6 +7,7 @@
* incognito: {boolean} enabled/disabled
* needsReload: {Object} indicates that changes were made in Ghostery (pause, block, unblock) and the tab should be reloaded
* pageTiming {Object} window.performance data
* partialScan: {boolean} true if Ghostery was not there from the very start (main_frame load onwards)
* path: {string} everything after the first "/"
* prefetched: {boolean} indicates that the tab was prefetched and not part of the main window
* purplebox: {boolean} indicates that the purplebox.js script has been loaded on this tab
@@ -51,6 +52,7 @@ class TabInfo {
const numOfReloads = this.getTabInfoPersist(tab_id, 'numOfReloads') || 0;
const info = {
needsReload: { changes: {} },
partialScan: true,
prefetched: false,
purplebox: false,
rewards: false,
@@ -68,12 +70,7 @@ class TabInfo {
};

if (tab_url) {
const parsed = processUrl(tab_url);
info.url = tab_url;
info.protocol = parsed.protocol;
info.host = parsed.host;
info.path = parsed.path;
info.hash = parsed.anchor;
this._updateUrl(tab_id, tab_url);
}

this._tabInfo[tab_id] = info;
@@ -180,6 +177,7 @@ class TabInfo {
this._tabInfo[tab_id].host = parsed.host;
this._tabInfo[tab_id].path = parsed.path;
this._tabInfo[tab_id].hash = parsed.anchor;
this._tabInfo[tab_id].partialScan = false;
}
}

ProTip! Use n and p to navigate between commits in a pull request.