@@ -230,6 +230,9 @@ export class WebRequestApi {
230
230
RequestEvents . onCompleted . addListener ( WebRequestApi . onCompleted ) ;
231
231
232
232
// browser.webNavigation Events
233
+ // Note: We need to force set matching result in Opera before run `WebRequestApi.onCommitted`
234
+ // TODO: remove this when Opera bug is fixed.
235
+ browser . webNavigation . onCommitted . addListener ( WebRequestApi . onCommittedOperaHook ) ;
233
236
browser . webNavigation . onCommitted . addListener ( WebRequestApi . onCommitted ) ;
234
237
browser . webNavigation . onDOMContentLoaded . addListener ( WebRequestApi . onDomContentLoaded ) ;
235
238
browser . webNavigation . onCompleted . addListener ( WebRequestApi . deleteFrameContext ) ;
@@ -693,33 +696,6 @@ export class WebRequestApi {
693
696
url,
694
697
} = details ;
695
698
696
- /**
697
- * There is Opera bug that prevents firing WebRequest events for document and subdocument requests.
698
- * We now handle this by checking if matching result exists for main frame and if not - we create it.
699
- *
700
- * TODO remove this when Opera bug is fixed.
701
- */
702
- if ( isOpera && frameId === MAIN_FRAME_ID ) {
703
- const tabContext = tabsApi . getTabContext ( tabId ) ;
704
- if ( ! tabContext ) {
705
- return ;
706
- }
707
-
708
- const frame = tabContext . frames . get ( frameId ) ;
709
- if ( ! frame || frame . matchingResult ) {
710
- return ;
711
- }
712
-
713
- const matchingResult = engineApi . matchRequest ( {
714
- requestUrl : url ,
715
- frameUrl : url ,
716
- requestType : RequestType . Document ,
717
- frameRule : tabContext . mainFrameRule ,
718
- } ) ;
719
-
720
- frame . matchingResult = matchingResult ;
721
- }
722
-
723
699
WebRequestApi . injectCosmetic ( {
724
700
frameId,
725
701
tabId,
@@ -877,4 +853,45 @@ export class WebRequestApi {
877
853
*/
878
854
setTimeout ( ( ) => tabContext . frames . delete ( frameId ) , FRAME_DELETION_TIMEOUT ) ;
879
855
}
856
+
857
+ /**
858
+ * On committed web navigation event handler only for Opera.
859
+ *
860
+ * There is Opera bug that prevents firing WebRequest events for document
861
+ * and subdocument requests.
862
+ * We now handle this by checking if matching result exists for main frame
863
+ * and if not - we force create it.
864
+ *
865
+ * TODO: remove this when Opera bug is fixed.
866
+ *
867
+ * @param details Event details.
868
+ */
869
+ private static onCommittedOperaHook ( details : WebNavigation . OnCommittedDetailsType ) : void {
870
+ const {
871
+ frameId,
872
+ tabId,
873
+ url,
874
+ } = details ;
875
+
876
+ if ( isOpera && frameId === MAIN_FRAME_ID ) {
877
+ const tabContext = tabsApi . getTabContext ( tabId ) ;
878
+ if ( ! tabContext ) {
879
+ return ;
880
+ }
881
+
882
+ const frame = tabContext . frames . get ( frameId ) ;
883
+ if ( ! frame || frame . matchingResult ) {
884
+ return ;
885
+ }
886
+
887
+ const matchingResult = engineApi . matchRequest ( {
888
+ requestUrl : url ,
889
+ frameUrl : url ,
890
+ requestType : RequestType . Document ,
891
+ frameRule : tabContext . mainFrameRule ,
892
+ } ) ;
893
+
894
+ frame . matchingResult = matchingResult ;
895
+ }
896
+ }
880
897
}
0 commit comments