@@ -888,10 +888,27 @@ uBOScope.start = function() {
888
888
889
889
// When there is no matching request entry, this means a request was
890
890
// 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 = / ^ d a t a : / ;
906
+
892
907
self . browser . webRequest . onBeforeRedirect . addListener (
893
908
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 ) ) {
895
912
requestIds . delete ( details . requestId ) ;
896
913
ubo . processRequest ( details , true ) ;
897
914
updateTabBadge ( details . tabId ) ;
0 commit comments