@@ -96,7 +96,7 @@ function registerForBeforeRequest (session, partition) {
96
96
}
97
97
}
98
98
99
- if ( shouldIgnoreUrl ( details . url ) ) {
99
+ if ( shouldIgnoreUrl ( details ) ) {
100
100
cb ( { } )
101
101
return
102
102
}
@@ -195,7 +195,7 @@ function registerForBeforeRedirect (session, partition) {
195
195
// Note that onBeforeRedirect listener doesn't take a callback
196
196
session . webRequest . onBeforeRedirect ( function ( details ) {
197
197
// Using an electron binary which isn't from Brave
198
- if ( shouldIgnoreUrl ( details . url ) ) {
198
+ if ( shouldIgnoreUrl ( details ) ) {
199
199
return
200
200
}
201
201
for ( let i = 0 ; i < beforeRedirectFilteringFns . length ; i ++ ) {
@@ -222,7 +222,7 @@ function registerForBeforeSendHeaders (session, partition) {
222
222
223
223
session . webRequest . onBeforeSendHeaders ( function ( details , cb ) {
224
224
// Using an electron binary which isn't from Brave
225
- if ( shouldIgnoreUrl ( details . url ) ) {
225
+ if ( shouldIgnoreUrl ( details ) ) {
226
226
cb ( { } )
227
227
return
228
228
}
@@ -295,7 +295,7 @@ function registerForHeadersReceived (session, partition) {
295
295
// Note that onBeforeRedirect listener doesn't take a callback
296
296
session . webRequest . onHeadersReceived ( function ( details , cb ) {
297
297
// Using an electron binary which isn't from Brave
298
- if ( shouldIgnoreUrl ( details . url ) ) {
298
+ if ( shouldIgnoreUrl ( details ) ) {
299
299
cb ( { } )
300
300
return
301
301
}
@@ -558,16 +558,30 @@ function initForPartition (partition) {
558
558
559
559
const filterableProtocols = [ 'http:' , 'https:' ]
560
560
561
- function shouldIgnoreUrl ( url ) {
561
+ function shouldIgnoreUrl ( details ) {
562
+ // internal requests
563
+ if ( details . tabId === - 1 ) {
564
+ return true
565
+ }
566
+
562
567
// Ensure host is well-formed (RFC 1035) and has a non-empty hostname
568
+ try {
569
+ const firstPartyUrl = urlParse ( details . firstPartyUrl )
570
+ if ( ! filterableProtocols . includes ( firstPartyUrl . protocol ) ) {
571
+ return true
572
+ }
573
+ } catch ( e ) {
574
+ console . warn ( 'Error parsing ' + details . firstPartyUrl )
575
+ }
576
+
563
577
try {
564
578
// TODO(bridiver) - handle RFS check and cancel http/https requests with 0 or > 255 length hostames
565
- const parsedUrl = urlParse ( url )
579
+ const parsedUrl = urlParse ( details . url )
566
580
if ( filterableProtocols . includes ( parsedUrl . protocol ) ) {
567
581
return false
568
582
}
569
583
} catch ( e ) {
570
- console . warn ( 'Error parsing ' + url )
584
+ console . warn ( 'Error parsing ' + details . url )
571
585
}
572
586
return true
573
587
}
0 commit comments