Skip to content

Commit 70bcf27

Browse files
committed
feat(human-emulators): ghost emulator
fix(replay): realtime playback, doctype
1 parent 240bea6 commit 70bcf27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1406
-358
lines changed

core-interfaces/IHumanEmulator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { IInteractionGroups, IInteractionStep } from './IInteractions';
2+
import IInteractionsHelper from './IInteractionsHelper';
3+
import IPoint from './IPoint';
24

35
export default interface IHumanEmulator {
46
playInteractions(
57
interactions: IInteractionGroups,
68
run: (interaction: IInteractionStep) => Promise<void>,
9+
helper?: IInteractionsHelper,
710
);
11+
getStartingMousePoint?(helper?: IInteractionsHelper): Promise<IPoint>;
812
}

core-interfaces/IInteractions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface IInteractionStep {
1313
mouseButton?: IMouseButton;
1414
keyboardCommands?: IKeyboardCommand[];
1515
keyboardDelayBetween?: number;
16+
keyboardKeyupDelay?: number;
1617
delayNode?: IJsPath;
1718
delayElement?: IJsPath;
1819
delayMillis?: number;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { IMousePosition } from './IInteractions';
2+
import IRect from './IRect';
3+
import IPoint from './IPoint';
4+
import IViewport from './IViewport';
5+
6+
export default interface IInteractionsHelper {
7+
lookupBoundingRect(mousePosition: IMousePosition): Promise<IRect & { elementTag?: string }>;
8+
mousePosition: IPoint;
9+
scrollOffset: Promise<IPoint>;
10+
viewport: IViewport;
11+
}

core-interfaces/IPoint.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default interface IPoint {
2+
x: number;
3+
y: number;
4+
}

core-interfaces/IRect.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default interface IRect {
2+
x: number;
3+
y: number;
4+
width: number;
5+
height: number;
6+
}

core-interfaces/IWindowOffset.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default interface IWindowOffset {
2+
innerWidth: number;
3+
innerHeight: number;
4+
pageXOffset: number;
5+
pageYOffset: number;
6+
}

core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ export default class Core implements ICore {
319319
const promises: Promise<void>[] = [];
320320
for (const key of tabIds ?? Object.keys(Core.byTabId)) {
321321
const core = Core.byTabId[key];
322+
if (!core) continue;
322323
delete Core.byTabId[key];
323324
promises.push(core.close());
324325
}

core/lib/DomEnv.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs';
22
import { IJsPath } from 'awaited-dom/base/AwaitedPath';
33
import { IRequestInit } from 'awaited-dom/base/interfaces/official';
4-
import Log from '@secret-agent/commons/Logger';
4+
import Log from '@secret-agent/commons/Logger';
55
import Typeson from 'typeson';
66
import TypesonRegistry from 'typeson-registry/dist/presets/builtin';
77
import IElementRect from '@secret-agent/injected-scripts/interfaces/IElementRect';
@@ -10,6 +10,7 @@ import IAttachedState from '@secret-agent/injected-scripts/interfaces/IAttachedS
1010
import { IPuppetPage } from '@secret-agent/puppet-interfaces/IPuppetPage';
1111
import injectedSourceUrl from '@secret-agent/core-interfaces/injectedSourceUrl';
1212
import { IBoundLog } from '@secret-agent/core-interfaces/ILog';
13+
import IWindowOffset from '@secret-agent/core-interfaces/IWindowOffset';
1314
import DomEnvError from './DomEnvError';
1415
import { Serializable } from '../interfaces/ISerializable';
1516

@@ -146,12 +147,7 @@ export default class DomEnv {
146147
}
147148

148149
public getWindowOffset() {
149-
return this.runIsolatedFn<{
150-
innerWidth: number;
151-
innerHeight: number;
152-
pageXOffset: number;
153-
pageYOffset: number;
154-
}>('window.SecretAgent.JsPath.getWindowOffset');
150+
return this.runIsolatedFn<IWindowOffset>('window.SecretAgent.JsPath.getWindowOffset');
155151
}
156152

157153
public locationHref() {

core/lib/HumanEmulators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { pickRandom } from '@secret-agent/commons/utils';
22
import IHumanEmulatorClass from '@secret-agent/core-interfaces/IHumanEmulatorClass';
3-
import HumanEmulatorBasic from '@secret-agent/emulate-humans-basic';
3+
import HumanEmulatorGhost from '@secret-agent/emulate-humans-ghost';
44

55
export default class HumanEmulators {
66
private static readonly emulatorsById: { [id: string]: IHumanEmulatorClass } = {};
@@ -35,4 +35,4 @@ export default class HumanEmulators {
3535
}
3636
}
3737

38-
HumanEmulators.load(HumanEmulatorBasic);
38+
HumanEmulators.load(HumanEmulatorGhost);

0 commit comments

Comments
 (0)