Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 5d83991

Browse files
committed
fix difference in behavior observed with Firefox webRequest API
1 parent 3cad954 commit 5d83991

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

js/start.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,27 @@ uBOScope.start = function() {
888888

889889
// When there is no matching request entry, this means a request was
890890
// redirected to a data: URI by an extension.
891-
// See <https://developer.chrome.com/extensions/webRequest>.
891+
// See <https://developer.chrome.com/extensions/webRequest>:
892+
// > The web request API guarantees that for each request either
893+
// > onCompleted or onErrorOccurred is fired as the final event with one
894+
// > exception: If a request is redirected to a data:// URL,
895+
// > onBeforeRedirect is the last reported event.
896+
//
897+
// When a URL is redirected to a data: URI:
898+
// - Chromium: onSendHeaders is never called.
899+
// - Firefox: onSendHeaders IS called.
900+
// So an extra test is needed to find out whether there was an actual
901+
// connection to a remote server. Currently testing status code, but this
902+
// will be an issue if ever Firefox aligns its behavior to that of
903+
// Chromium, as the latter contains a valid status code of 307. If this
904+
// ever happens, maybe using details.ip?
905+
let reInternalURL = /^data:/;
906+
892907
self.browser.webRequest.onBeforeRedirect.addListener(
893908
function(details) {
894-
if ( requestIds.has(details.requestId) === false ) {
909+
let noConnection = requestIds.has(details.requestId) === false ||
910+
!details.statusCode;
911+
if ( noConnection && reInternalURL.test(details.redirectUrl) ) {
895912
requestIds.delete(details.requestId);
896913
ubo.processRequest(details, true);
897914
updateTabBadge(details.tabId);

0 commit comments

Comments
 (0)