2020import debounce from 'lodash/debounce' ;
2121import Browser from 'webextension-polyfill' ;
2222import {
23+ ElementLocator ,
2324 ZestStatement ,
2425 ZestStatementComment ,
2526 ZestStatementElementClick ,
@@ -72,13 +73,15 @@ class Recorder {
7273
7374 async sendZestScriptToZAP (
7475 zestStatement : ZestStatement ,
75- sendCache = true
76+ params : { sendCache : boolean ; notify : boolean }
7677 ) : Promise < number > {
77- if ( sendCache ) {
78+ if ( params . sendCache ) {
7879 this . handleCachedSubmit ( ) ;
7980 }
8081 // console.log('ZAP Sending statement', zestStatement);
81- this . notify ( zestStatement ) ;
82+ if ( params . notify ) {
83+ this . notify ( zestStatement ) ;
84+ }
8285 return Browser . runtime . sendMessage ( {
8386 type : ZEST_SCRIPT ,
8487 data : zestStatement . toJSON ( ) ,
@@ -99,17 +102,24 @@ class Recorder {
99102 return waited ;
100103 }
101104
105+ sendScrollToToZap ( elementLocator : ElementLocator , waitForMsec : number ) : void {
106+ this . sendZestScriptToZAP (
107+ new ZestStatementElementScrollTo ( elementLocator , waitForMsec ) ,
108+ { sendCache : false , notify : false }
109+ ) ;
110+ }
111+
102112 handleCachedSubmit ( ) : void {
103113 if ( this . cachedSubmit ) {
104- this . sendZestScriptToZAP (
105- new ZestStatementElementScrollTo (
106- this . cachedSubmit . elementLocator ,
107- this . getWaited ( )
108- ) ,
109- false
114+ this . sendScrollToToZap (
115+ this . cachedSubmit . elementLocator ,
116+ this . getWaited ( )
110117 ) ;
111118 // console.log('ZAP Sending cached submit', this.cachedSubmit);
112- this . sendZestScriptToZAP ( this . cachedSubmit , false ) ;
119+ this . sendZestScriptToZAP ( this . cachedSubmit , {
120+ sendCache : false ,
121+ notify : true ,
122+ } ) ;
113123 delete this . cachedSubmit ;
114124 this . cachedTimeStamp = - 1 ;
115125 }
@@ -121,14 +131,20 @@ class Recorder {
121131 }
122132 if ( this . curLevel > level ) {
123133 while ( this . curLevel > level ) {
124- this . sendZestScriptToZAP ( new ZestStatementSwitchToFrame ( - 1 ) ) ;
134+ this . sendZestScriptToZAP ( new ZestStatementSwitchToFrame ( - 1 ) , {
135+ sendCache : true ,
136+ notify : true ,
137+ } ) ;
125138 this . curLevel -= 1 ;
126139 }
127140 this . curFrame = frameIndex ;
128141 } else {
129142 this . curLevel += 1 ;
130143 this . curFrame = frameIndex ;
131- this . sendZestScriptToZAP ( new ZestStatementSwitchToFrame ( frameIndex ) ) ;
144+ this . sendZestScriptToZAP ( new ZestStatementSwitchToFrame ( frameIndex ) , {
145+ sendCache : true ,
146+ notify : true ,
147+ } ) ;
132148 }
133149 if ( this . curLevel !== level ) {
134150 console . log ( 'ZAP Error in switching frames' ) ;
@@ -154,12 +170,10 @@ class Recorder {
154170 return ;
155171 }
156172
173+ this . sendScrollToToZap ( elementLocator , waited ) ;
157174 this . sendZestScriptToZAP (
158- new ZestStatementElementScrollTo ( elementLocator , waited ) ,
159- false
160- ) ;
161- this . sendZestScriptToZAP (
162- new ZestStatementElementClick ( elementLocator , waited )
175+ new ZestStatementElementClick ( elementLocator , waited ) ,
176+ { sendCache : true , notify : true }
163177 ) ;
164178 // click on target element
165179 }
@@ -206,17 +220,14 @@ class Recorder {
206220 // The cached submit was not on the same element, so send it
207221 this . handleCachedSubmit ( ) ;
208222 }
209- this . sendZestScriptToZAP (
210- new ZestStatementElementScrollTo ( elementLocator , waited ) ,
211- false
212- ) ;
223+ this . sendScrollToToZap ( elementLocator , waited ) ;
213224 this . sendZestScriptToZAP (
214225 new ZestStatementElementSendKeys (
215226 elementLocator ,
216227 ( event . target as HTMLInputElement ) . value ,
217228 waited
218229 ) ,
219- false
230+ { sendCache : false , notify : true }
220231 ) ;
221232 // Now send the cached submit, if there still is one
222233 this . handleCachedSubmit ( ) ;
@@ -468,13 +479,15 @@ class Recorder {
468479 new ZestStatementComment (
469480 `Recorded by ${ Browser . runtime . getManifest ( ) . name } ` +
470481 `${ Browser . runtime . getManifest ( ) . version } on ${ navigator . userAgent } `
471- )
482+ ) ,
483+ { sendCache : true , notify : true }
472484 ) ;
473485 this . sendZestScriptToZAP (
474486 new ZestStatementLaunchBrowser (
475487 this . getBrowserName ( ) ,
476488 loginUrl !== '' ? loginUrl : window . location . href
477- )
489+ ) ,
490+ { sendCache : true , notify : true }
478491 ) ;
479492 this . handleResize ( ) ;
480493 }
0 commit comments