Skip to content

Commit 9357d50

Browse files
authored
Merge pull request #281 from thc202/ignore-scroll-to
Do not notify scroll to statements
2 parents b520d2d + 2f85ef6 commit 9357d50

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
77

8+
### Changed
9+
- Do not notify synthetic scroll to statements, which are only added to help with replay not as direct result of user actions.
10+
811
### Fixed
912
- Ignore events on non-visible elements, which will fail on replay.
1013
- Ignore click after submit, since the former is a side effect of the latter.

CHANGELOG.rec.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
77

8+
### Changed
9+
- Do not notify synthetic scroll to statements, which are only added to help with replay not as direct result of user actions.
10+
811
### Fixed
912
- Ignore events on non-visible elements, which will fail on replay.
1013
- Ignore click after submit, since the former is a side effect of the latter.

source/ContentScript/recorder.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import debounce from 'lodash/debounce';
2121
import Browser from 'webextension-polyfill';
2222
import {
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

Comments
 (0)