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