Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ext/background.js

Issue 29418659: Issue 5130 - Changes listener to register <all_urls> and filter non ws http requests (Closed)
Patch Set: Created April 20, 2017, 7:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ext/background.js
===================================================================
--- a/ext/background.js
+++ b/ext/background.js
@@ -558,16 +558,24 @@
}
}
});
});
});
chrome.webRequest.onBeforeRequest.addListener(details =>
{
+ // Filter out requests from non web protocols since Chrome version
+ // 58 added support for webSocket connections to the webRequests API
Jon Sonesen 2017/04/20 19:19:58 this comment should likely be improved. perhaps we
Sebastian Noack 2017/04/20 19:34:15 "Filter out requests from non web protocols. Ideal
Jon Sonesen 2017/04/20 19:53:06 Acknowledged. Thank you, I think that is good.
+ let blockURLs = new RegExp("https?|wss?");
+ let url = new URL(details.url);
Sebastian Noack 2017/04/20 19:34:15 We are now creating two URL objects, one to valida
Jon Sonesen 2017/04/20 19:53:06 Ah, sorry about that.
+ if (!blockURLs.exec(url.protocol))
Sebastian Noack 2017/04/20 19:34:15 Since the regular expression doesn't make the code
Sebastian Noack 2017/04/20 19:36:22 I accidentally inverted the logic, should be of co
Jon Sonesen 2017/04/20 19:53:06 Yeah, happy to use this instead.
+ {
Sebastian Noack 2017/04/20 19:34:15 We generally omit the braces if there is only one
Jon Sonesen 2017/04/20 19:53:06 Done.
+ return {cancel: false};
Sebastian Noack 2017/04/20 19:34:15 For consistency with the other bailout condition b
Jon Sonesen 2017/04/20 19:53:06 Done.
+ }
// The high-level code isn't interested in requests that aren't
// related to a tab or requests loading a top-level document,
// those should never be blocked.
if (details.tabId == -1 || details.type == "main_frame")
return;
// We are looking for the frame that contains the element which
// has triggered this request. For most requests (e.g. images) we
@@ -588,17 +596,17 @@
type.toUpperCase(),
new Page({id: details.tabId}),
frame
);
if (results.indexOf(false) != -1)
return {cancel: true};
}
- }, {urls: ["https://*/*", "http://*/*", "ws://*/*", "wss://*/*"]}, ["blocking"]);
+ }, {urls: ["<all_urls>"]}, ["blocking"]);
/* Message passing */
chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) =>
{
let sender = {};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld