Skip to content

Commit

Permalink
improve mouse record and replay (#49)
Browse files Browse the repository at this point in the history
Increase the throttle value of collecting mouse move and add a
transition time to the replayer's mouse. This may decrease the
size of mouse move data and make the replay movement more smooth.
Another change is to move and hover when click event is replayed.
This is to improve the replay of some programmatic click, such as
E2E tests.
  • Loading branch information
Yuyz0112 authored Jan 25, 2019
1 parent 6abf4fd commit 2233020
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function initMousemoveObserver(cb: mousemoveCallBack): listenerHandler {
});
wrappedCb();
},
20,
50,
{
trailing: false,
},
Expand Down
19 changes: 12 additions & 7 deletions src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,7 @@ export class Replayer {
d.positions.forEach(p => {
const action = {
doAction: () => {
this.mouse.style.left = `${p.x}px`;
this.mouse.style.top = `${p.y}px`;
const target = mirror.getNode(p.id);
if (!target) {
return this.warnNodeNotFound(d, p.id);
}
this.hoverElements((target as Node) as Element);
this.moveAndHover(d, p.x, p.y, p.id);
},
delay: p.timeOffset + e.timestamp - this.baselineTime,
};
Expand Down Expand Up @@ -475,6 +469,7 @@ export class Replayer {
* clicked at this moment.
*/
if (!isSync) {
this.moveAndHover(d, d.x, d.y, d.id);
this.mouse.classList.remove('active');
// tslint:disable-next-line
void this.mouse.offsetWidth;
Expand Down Expand Up @@ -577,6 +572,16 @@ export class Replayer {
}
}

private moveAndHover(d: incrementalData, x: number, y: number, id: number) {
this.mouse.style.left = `${x}px`;
this.mouse.style.top = `${y}px`;
const target = mirror.getNode(id);
if (!target) {
return this.warnNodeNotFound(d, id);
}
this.hoverElements((target as Node) as Element);
}

private hoverElements(el: Element) {
this.iframe
.contentDocument!.querySelectorAll('.\\:hover')
Expand Down
1 change: 1 addition & 0 deletions src/replay/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
position: absolute;
width: 20px;
height: 20px;
transition: 0.05s linear;
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
Expand Down

0 comments on commit 2233020

Please sign in to comment.