@@ -54,18 +54,21 @@ const NetFilteringResultCache = class {
54
54
return this ;
55
55
}
56
56
57
+ // https://github.com/gorhill/uBlock/issues/3619
58
+ // Don't collapse redirected resources
57
59
rememberResult ( fctxt , result ) {
58
60
if ( fctxt . tabId <= 0 ) { return ; }
59
61
if ( this . results . size === 0 ) {
60
62
this . pruneAsync ( ) ;
61
63
}
62
- const key = fctxt . getDocHostname ( ) + ' ' + fctxt . type + ' ' + fctxt . url ;
64
+ const key = ` ${ fctxt . getDocHostname ( ) } ${ fctxt . type } ${ fctxt . url } ` ;
63
65
this . results . set ( key , {
64
- result : result ,
66
+ result,
67
+ redirectURL : fctxt . redirectURL ,
65
68
logData : fctxt . filter ,
66
69
tstamp : Date . now ( )
67
70
} ) ;
68
- if ( result !== 1 ) { return ; }
71
+ if ( result !== 1 || fctxt . redirectURL !== undefined ) { return ; }
69
72
const now = Date . now ( ) ;
70
73
this . blocked . set ( key , now ) ;
71
74
this . hash = now ;
@@ -76,16 +79,17 @@ const NetFilteringResultCache = class {
76
79
if ( this . blocked . size === 0 ) {
77
80
this . pruneAsync ( ) ;
78
81
}
82
+ if ( fctxt . redirectURL !== undefined ) { return ; }
79
83
const now = Date . now ( ) ;
80
84
this . blocked . set (
81
- fctxt . getDocHostname ( ) + ' ' + fctxt . type + ' ' + fctxt . url ,
85
+ ` ${ fctxt . getDocHostname ( ) } ${ fctxt . type } ${ fctxt . url } ` ,
82
86
now
83
87
) ;
84
88
this . hash = now ;
85
89
}
86
90
87
- forgetResult ( fctxt ) {
88
- const key = `${ fctxt . getDocHostname ( ) } ${ fctxt . type } ${ fctxt . url } ` ;
91
+ forgetResult ( docHostname , type , url ) {
92
+ const key = `${ docHostname } ${ type } ${ url } ` ;
89
93
this . results . delete ( key ) ;
90
94
this . blocked . delete ( key ) ;
91
95
}
@@ -171,7 +175,7 @@ const FrameStore = class {
171
175
init ( frameURL ) {
172
176
this . t0 = Date . now ( ) ;
173
177
this . exceptCname = undefined ;
174
- this . clickToLoad = 0 ;
178
+ this . clickToLoad = false ;
175
179
this . rawURL = frameURL ;
176
180
if ( frameURL !== undefined ) {
177
181
this . hostname = vAPI . hostnameFromURI ( frameURL ) ;
@@ -559,6 +563,7 @@ const PageStore = class {
559
563
if ( cacheableResult ) {
560
564
const entry = this . netFilteringCache . lookupResult ( fctxt ) ;
561
565
if ( entry !== undefined ) {
566
+ fctxt . redirectURL = entry . redirectURL ;
562
567
fctxt . filter = entry . logData ;
563
568
return entry . result ;
564
569
}
@@ -607,11 +612,11 @@ const PageStore = class {
607
612
}
608
613
}
609
614
610
- // Click-to-load:
615
+ // Click-to-load?
611
616
// When frameId is not -1, the resource is always sub_frame.
612
617
if ( result === 1 && fctxt . frameId !== - 1 ) {
613
- const docStore = this . getFrameStore ( fctxt . frameId ) ;
614
- if ( docStore !== null && docStore . clickToLoad !== 0 ) {
618
+ const frameStore = this . getFrameStore ( fctxt . frameId ) ;
619
+ if ( frameStore !== null && frameStore . clickToLoad ) {
615
620
result = 2 ;
616
621
if ( µb . logger . enabled ) {
617
622
fctxt . setFilter ( {
@@ -623,13 +628,20 @@ const PageStore = class {
623
628
}
624
629
}
625
630
631
+ // https://github.com/gorhill/uBlock/issues/949
632
+ // Redirect blocked request?
633
+ if ( result === 1 && µb . hiddenSettings . ignoreRedirectFilters !== true ) {
634
+ const redirectURL = µb . redirectEngine . toURL ( fctxt ) ;
635
+ if ( redirectURL !== undefined ) {
636
+ fctxt . redirectURL = redirectURL ;
637
+ this . internalRedirectionCount += 1 ;
638
+ }
639
+ }
640
+
626
641
if ( cacheableResult ) {
627
642
this . netFilteringCache . rememberResult ( fctxt , result ) ;
628
- } else if (
629
- result === 1 &&
630
- this . collapsibleResources . has ( requestType )
631
- ) {
632
- this . netFilteringCache . rememberBlock ( fctxt , true ) ;
643
+ } else if ( result === 1 && this . collapsibleResources . has ( requestType ) ) {
644
+ this . netFilteringCache . rememberBlock ( fctxt ) ;
633
645
}
634
646
635
647
return result ;
@@ -727,7 +739,12 @@ const PageStore = class {
727
739
if ( frameStore === null ) {
728
740
frameStore = this . setFrameURL ( frameId , frameURL ) ;
729
741
}
730
- frameStore . clickToLoad = Date . now ( ) ;
742
+ this . netFilteringCache . forgetResult (
743
+ this . tabHostname ,
744
+ 'sub_frame' ,
745
+ frameURL
746
+ ) ;
747
+ frameStore . clickToLoad = true ;
731
748
}
732
749
733
750
shouldExceptCname ( fctxt ) {
@@ -776,24 +793,16 @@ const PageStore = class {
776
793
// content script-side (i.e. `iframes` -- unlike `img`).
777
794
if ( Array . isArray ( resources ) && resources . length !== 0 ) {
778
795
for ( const resource of resources ) {
779
- const result = this . filterRequest (
796
+ this . filterRequest (
780
797
fctxt . setType ( resource . type ) . setURL ( resource . url )
781
798
) ;
782
- if ( result === 1 && µb . redirectEngine . toURL ( fctxt ) ) {
783
- this . forgetBlockedResource ( fctxt ) ;
784
- }
785
799
}
786
800
}
787
801
if ( this . netFilteringCache . hash === response . hash ) { return ; }
788
802
response . hash = this . netFilteringCache . hash ;
789
803
response . blockedResources =
790
804
this . netFilteringCache . lookupAllBlocked ( fctxt . getDocHostname ( ) ) ;
791
805
}
792
-
793
- forgetBlockedResource ( fctxt ) {
794
- if ( this . collapsibleResources . has ( fctxt . type ) === false ) { return ; }
795
- this . netFilteringCache . forgetResult ( fctxt ) ;
796
- }
797
806
} ;
798
807
799
808
PageStore . prototype . cacheableResults = new Set ( [
0 commit comments