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
Next
Refining onBeforeRequest handler.
  • Loading branch information
zarembsky committed Jul 16, 2018
commit 23d36e21c99848063143ff7576eb6e17702278c2
@@ -335,20 +335,27 @@ class EventHandlers {
return { cancel: false };
}

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

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

// get tab data from browser and update the new tabInfo entry
if(!tabInfo.getTabInfo(tab_id)) {
utils.getTab(tab_id, (tab) => {
const ti = tabInfo.getTabInfo(tab_id);
if (ti && ti.partialScan) {
tabInfo.setTabInfo(tab_id, 'url', tab.url);
if(!tabInfo.getTabInfo(tab_id)) {
tabInfo.create(tab_id, tab.url);
} else {
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)) {
@@ -7,7 +7,6 @@
* 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
@@ -52,7 +51,6 @@ class TabInfo {
const numOfReloads = this.getTabInfoPersist(tab_id, 'numOfReloads') || 0;
const info = {
needsReload: { changes: {} },
partialScan: true,
prefetched: false,
purplebox: false,
rewards: false,
@@ -76,7 +74,6 @@ class TabInfo {
info.host = parsed.host;
info.path = parsed.path;
info.hash = parsed.anchor;
info.partialScan = false;
}

this._tabInfo[tab_id] = info;
ProTip! Use n and p to navigate between commits in a pull request.