@speedkit/cli 4.51.0-run-control.3 → 4.51.0-run-control.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/build-info.json +3 -3
- package/dist/commands/onboarding/browser/click.js +1 -1
- package/dist/services/browser-fetch/device-emulation.d.ts +11 -0
- package/dist/services/browser-fetch/device-emulation.js +14 -0
- package/dist/services/onboarding/browse/browse-service.js +3 -0
- package/dist/services/onboarding/browser/emulate-device.js +36 -8
- package/dist/services/onboarding/control/browser-session.d.ts +14 -2
- package/dist/services/onboarding/control/browser-session.js +68 -31
- package/dist/services/onboarding/control/control-protocol.d.ts +2 -0
- package/dist/services/onboarding/onboarding-model.d.ts +10 -7
- package/dist/services/onboarding/onboarding-model.js +8 -8
- package/dist/services/onboarding/onboarding-service.js +3 -0
- package/dist/services/onboarding/spec/control/browser-session.spec.js +109 -7
- package/dist/services/onboarding/spec/control/fakes.js +1 -0
- package/dist/services/run-control/browser/run-browser-contexts.js +1 -1
- package/dist/services/run-control/spec/browser/run-browser-service.spec.js +1 -0
- package/oclif.manifest.json +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -909,7 +909,7 @@ EXAMPLES
|
|
|
909
909
|
|
|
910
910
|
## `sk onboarding browser click [SELECTOR]`
|
|
911
911
|
|
|
912
|
-
Click an element the way a visitor does — a trusted
|
|
912
|
+
Click an element the way a visitor does — a trusted click at its centre, a tap under touch emulation — by selector or by its text
|
|
913
913
|
|
|
914
914
|
```
|
|
915
915
|
USAGE
|
|
@@ -928,7 +928,8 @@ FLAGS
|
|
|
928
928
|
--timeout=<value> How long to wait for the run to answer, in ms. The default suits the op
|
|
929
929
|
|
|
930
930
|
DESCRIPTION
|
|
931
|
-
Click an element the way a visitor does — a trusted
|
|
931
|
+
Click an element the way a visitor does — a trusted click at its centre, a tap under touch emulation — by selector or
|
|
932
|
+
by its text
|
|
932
933
|
|
|
933
934
|
EXAMPLES
|
|
934
935
|
$ sk onboarding browser click '#onetrust-accept-btn-handler'
|
|
@@ -948,8 +949,8 @@ USAGE
|
|
|
948
949
|
[--dpr <value>] [--user-agent <value>] [--touch] [--reload] [--tab <value>]
|
|
949
950
|
|
|
950
951
|
ARGUMENTS
|
|
951
|
-
DEVICE (mobile|tablet|desktop|off)
|
|
952
|
-
|
|
952
|
+
DEVICE (mobile|tablet|desktop|off) The same profile as sk onboarding --device: screen, DPR, user agent, client hints
|
|
953
|
+
and touch. off puts back the state the run started with
|
|
953
954
|
|
|
954
955
|
FLAGS
|
|
955
956
|
--dpr=<value> Override the preset's device pixel ratio
|
package/dist/build-info.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RunControlCommand } from "../../../base/run-control-command.js";
|
|
2
2
|
import { BrowserClickBuildContext, RunBrowserServiceFactory, } from "../../../services/run-control/index.js";
|
|
3
3
|
export default class BrowserClick extends RunControlCommand {
|
|
4
|
-
static description = "Click an element the way a visitor does — a trusted
|
|
4
|
+
static description = "Click an element the way a visitor does — a trusted click at its centre, a tap under touch emulation — by selector or by its text";
|
|
5
5
|
static buildContext = BrowserClickBuildContext;
|
|
6
6
|
static args = BrowserClickBuildContext.args;
|
|
7
7
|
static flags = BrowserClickBuildContext.flags;
|
|
@@ -57,3 +57,14 @@ export declare function deviceForUserAgent(userAgent?: string): FetchDevice | un
|
|
|
57
57
|
* fingerprint matches; `sk onboarding --device desktop` presents Windows.
|
|
58
58
|
*/
|
|
59
59
|
export declare function deviceEmulation(browserVersionString: string, device: FetchDevice, platform?: string): DeviceEmulation;
|
|
60
|
+
/** A device as `sk onboarding` presents it: always with a viewport, also for the desktop. */
|
|
61
|
+
export type OnboardingDeviceEmulation = DeviceEmulation & {
|
|
62
|
+
viewport: Viewport;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The one device profile of `sk onboarding --device` and `sk onboarding browser emulate`: the
|
|
66
|
+
* {@link DEVICE_VIEWPORTS} screen, and the user agent and client hints of {@link deviceEmulation}.
|
|
67
|
+
*
|
|
68
|
+
* @param browserVersionString - `browser.version()`, e.g. `Chrome/146.0.7680.165`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function onboardingDeviceEmulation(browserVersionString: string, device: FetchDevice): OnboardingDeviceEmulation;
|
|
@@ -143,6 +143,20 @@ export function deviceEmulation(browserVersionString, device, platform = process
|
|
|
143
143
|
viewport,
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
+
/** `--device desktop` and `browser emulate desktop` present Chrome on Windows, the most common Chrome desktop in RUM (60%). */
|
|
147
|
+
const ONBOARDING_DESKTOP_PLATFORM = "win32";
|
|
148
|
+
/**
|
|
149
|
+
* The one device profile of `sk onboarding --device` and `sk onboarding browser emulate`: the
|
|
150
|
+
* {@link DEVICE_VIEWPORTS} screen, and the user agent and client hints of {@link deviceEmulation}.
|
|
151
|
+
*
|
|
152
|
+
* @param browserVersionString - `browser.version()`, e.g. `Chrome/146.0.7680.165`.
|
|
153
|
+
*/
|
|
154
|
+
export function onboardingDeviceEmulation(browserVersionString, device) {
|
|
155
|
+
return {
|
|
156
|
+
...deviceEmulation(browserVersionString, device, ONBOARDING_DESKTOP_PLATFORM),
|
|
157
|
+
viewport: DEVICE_VIEWPORTS[device],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
146
160
|
/**
|
|
147
161
|
* The client hints the headed desktop Chrome would send.
|
|
148
162
|
*
|
|
@@ -64,6 +64,9 @@ export class BrowseService {
|
|
|
64
64
|
origins: [origin],
|
|
65
65
|
reinstall: () => Promise.reject(new Error("browse mode installs no Speed Kit to reinstall")),
|
|
66
66
|
serviceWorkers: this.serviceWorkers,
|
|
67
|
+
touch: this.browserContext.getTouchEmulation()?.enabled === true,
|
|
68
|
+
deviceMetrics: this.browserContext.getDeviceMetricsOverride(),
|
|
69
|
+
setDeviceTouch: async (touch) => this.browserContext.setDeviceTouch?.(touch),
|
|
67
70
|
});
|
|
68
71
|
this.cli.successAction("ONBOARDING:BROWSE:BROWSER");
|
|
69
72
|
const navigation = await safe(page.goto(url));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { safe } from "../../../helpers/safe.js";
|
|
2
|
+
import { MAX_TOUCH_POINTS } from "../onboarding-model.js";
|
|
2
3
|
/**
|
|
3
4
|
* Emulates the device of `--device` on every page and Service Worker of `browser`: the ones open
|
|
4
5
|
* now, and every one opened later, by the CLI or by an external CDP client.
|
|
@@ -10,7 +11,39 @@ import { safe } from "../../../helpers/safe.js";
|
|
|
10
11
|
* The overrides live as long as this session, which lives as long as the browser connection.
|
|
11
12
|
*/
|
|
12
13
|
export async function emulateDevice(browser, browserContext) {
|
|
13
|
-
|
|
14
|
+
const pages = new Set();
|
|
15
|
+
let touch = browserContext.getTouchEmulation()?.enabled === true;
|
|
16
|
+
// `browser emulate` switches the touch here: Chrome re-applies this session's state on every navigation.
|
|
17
|
+
browserContext.setDeviceTouch = async (enabled) => {
|
|
18
|
+
touch = enabled;
|
|
19
|
+
for (const session of pages) {
|
|
20
|
+
if (session.detached)
|
|
21
|
+
pages.delete(session);
|
|
22
|
+
else
|
|
23
|
+
await setTouch(session, touch);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
await onEveryTarget(browser, async (session, targetInfo) => {
|
|
27
|
+
if (await emulateTarget(session, targetInfo, browserContext)) {
|
|
28
|
+
pages.add(session);
|
|
29
|
+
await setTouch(session, touch);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Touch emulation and the mouse-to-touch translation, on or off together.
|
|
35
|
+
*
|
|
36
|
+
* The translation makes a mouse click reach a touch-only handler in headed mode. Left on for a
|
|
37
|
+
* desktop, it swallows every CDP mouse press.
|
|
38
|
+
*/
|
|
39
|
+
async function setTouch(session, touch) {
|
|
40
|
+
await safe(session.send("Emulation.setTouchEmulationEnabled", touch
|
|
41
|
+
? { enabled: true, maxTouchPoints: MAX_TOUCH_POINTS }
|
|
42
|
+
: { enabled: false }));
|
|
43
|
+
await safe(session.send("Emulation.setEmitTouchEventsForMouse", {
|
|
44
|
+
enabled: touch,
|
|
45
|
+
configuration: "mobile",
|
|
46
|
+
}));
|
|
14
47
|
}
|
|
15
48
|
/** How long {@link onEveryTarget} holds a new target before it lets it run. */
|
|
16
49
|
const HOLD_MS = 4000;
|
|
@@ -52,6 +85,7 @@ export async function onEveryTarget(browser, handle, filter) {
|
|
|
52
85
|
});
|
|
53
86
|
return session;
|
|
54
87
|
}
|
|
88
|
+
/** Emulates the device on one target. True for a page, which {@link setTouch} then reaches. */
|
|
55
89
|
async function emulateTarget(session, targetInfo, browserContext) {
|
|
56
90
|
// Not the DevTools window that `devtools: true` docks next to a headed page.
|
|
57
91
|
const isPage = targetInfo.type === "page" && !targetInfo.url.startsWith("devtools:");
|
|
@@ -66,12 +100,6 @@ async function emulateTarget(session, targetInfo, browserContext) {
|
|
|
66
100
|
}
|
|
67
101
|
if (isPage) {
|
|
68
102
|
await safe(session.send("Emulation.setDeviceMetricsOverride", browserContext.getDeviceMetricsOverride()));
|
|
69
|
-
const touch = browserContext.getTouchEmulation();
|
|
70
|
-
await safe(session.send("Emulation.setTouchEmulationEnabled", touch));
|
|
71
|
-
// Without it a mouse click never reaches a touch-only handler in headed mode.
|
|
72
|
-
await safe(session.send("Emulation.setEmitTouchEventsForMouse", {
|
|
73
|
-
enabled: touch.enabled,
|
|
74
|
-
configuration: "mobile",
|
|
75
|
-
}));
|
|
76
103
|
}
|
|
104
|
+
return isPage;
|
|
77
105
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Browser, Page } from "puppeteer";
|
|
1
|
+
import { Browser, Page, Protocol } from "puppeteer";
|
|
2
2
|
import { BrowserActionData, BrowserResetScope, BrowserStateData, PageThreadState, BrowserClickData, BrowserEmulateData, CdpData, EmulatedDevice, TabInfo, EmulationState } from "./control-protocol.js";
|
|
3
3
|
import { DebugSession, DebugTransport } from "./debug-session.js";
|
|
4
4
|
import { NavigateWaitPoint } from "./navigate-wait.js";
|
|
@@ -135,6 +135,12 @@ export interface BrowserRunContext {
|
|
|
135
135
|
* `performance.mark` wrapper can only stop beside it.
|
|
136
136
|
*/
|
|
137
137
|
extensionArms?(): boolean;
|
|
138
|
+
/** Whether the run launched with touch emulation, as `--device mobile` does. */
|
|
139
|
+
touch?: boolean;
|
|
140
|
+
/** The screen the run launched with, from `--device`. `emulate off` puts it back. */
|
|
141
|
+
deviceMetrics?: Protocol.Emulation.SetDeviceMetricsOverrideRequest | null;
|
|
142
|
+
/** Switches the touch of `--device` itself. Its CDP session re-applies its own on every navigation. */
|
|
143
|
+
setDeviceTouch?(touch: boolean): Promise<void>;
|
|
138
144
|
/**
|
|
139
145
|
* The devtools extension's ID, or null when the run has none.
|
|
140
146
|
*
|
|
@@ -402,11 +408,17 @@ export declare class BrowserSession implements BrowserController, PreloadTranspo
|
|
|
402
408
|
rawCdp(method: string, params?: Record<string, unknown>): Promise<CdpData>;
|
|
403
409
|
/**
|
|
404
410
|
* Click an element the way a person does: scrolled into view, then a mouse
|
|
405
|
-
* press and release at its centre, dispatched by the browser.
|
|
411
|
+
* press and release at its centre, dispatched by the browser. Under touch
|
|
412
|
+
* emulation it is a tap instead: Chrome makes the touchstart, touchend,
|
|
413
|
+
* mousedown, mouseup and click from it, as on a phone.
|
|
406
414
|
*
|
|
407
415
|
* Not `element.click()`: that event is untrusted, and a consent banner or an
|
|
408
416
|
* add-to-cart handler that checks `isTrusted` ignores it — which is exactly
|
|
409
417
|
* the tracking this exists to verify.
|
|
418
|
+
*
|
|
419
|
+
* Not a mouse press under touch emulation: `--device` turns on
|
|
420
|
+
* `Emulation.setEmitTouchEventsForMouse`, and Chrome then never answers
|
|
421
|
+
* `Input.dispatchMouseEvent` for the press.
|
|
410
422
|
*/
|
|
411
423
|
click(target: ClickTarget): Promise<BrowserClickData>;
|
|
412
424
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DebugSession } from "./debug-session.js";
|
|
2
2
|
import { WAIT_MARKS, WAIT_PROBE, decideWait, } from "./navigate-wait.js";
|
|
3
|
-
import {
|
|
3
|
+
import { onboardingDeviceEmulation } from "../../browser-fetch/device-emulation.js";
|
|
4
4
|
import { onEveryTarget } from "../browser/emulate-device.js";
|
|
5
5
|
import { PreloadRegistry } from "./preload-registry.js";
|
|
6
6
|
import { PanelNotFoundError, showDevtoolsPanel, } from "../browser/extension/devtools-panel.js";
|
|
@@ -48,16 +48,6 @@ const PANEL_APPEAR_MS = 10_000;
|
|
|
48
48
|
const WORKER_SETTLE_MS = 5000;
|
|
49
49
|
/** A full-page capture of a long customer page is megabytes of PNG. */
|
|
50
50
|
const SCREENSHOT_MS = 30_000;
|
|
51
|
-
/**
|
|
52
|
-
* The devices `emulate` presents. Mobile is the phone the debugging scripts
|
|
53
|
-
* used, 390×844 at DPR 3; desktop is a full-HD window. The user agents come from
|
|
54
|
-
* {@link deviceEmulation}, derived from the running Chrome.
|
|
55
|
-
*/
|
|
56
|
-
const EMULATED = {
|
|
57
|
-
mobile: { width: 390, height: 844, dpr: 3, mobile: true, touch: true },
|
|
58
|
-
tablet: { width: 834, height: 1112, dpr: 2, mobile: true, touch: true },
|
|
59
|
-
desktop: { width: 1920, height: 1080, dpr: 1, mobile: false, touch: false },
|
|
60
|
-
};
|
|
61
51
|
export class NoSuchElementError extends Error {
|
|
62
52
|
code = "NO_SUCH_ELEMENT";
|
|
63
53
|
}
|
|
@@ -511,15 +501,16 @@ export class BrowserSession {
|
|
|
511
501
|
serviceWorkers: [],
|
|
512
502
|
};
|
|
513
503
|
}
|
|
514
|
-
|
|
515
|
-
const device =
|
|
504
|
+
// The same profile as `--device`, so a run started on a device and one switched to it match.
|
|
505
|
+
const device = onboardingDeviceEmulation((await this.browser?.version()) ?? "", request.device);
|
|
506
|
+
const preset = device.viewport;
|
|
516
507
|
const state = {
|
|
517
508
|
device: request.device,
|
|
518
509
|
width: request.width ?? preset.width,
|
|
519
510
|
height: request.height ?? preset.height,
|
|
520
|
-
dpr: request.dpr ?? preset.
|
|
521
|
-
mobile: preset.
|
|
522
|
-
touch: request.touch ?? preset.
|
|
511
|
+
dpr: request.dpr ?? preset.deviceScaleFactor ?? 1,
|
|
512
|
+
mobile: preset.isMobile ?? false,
|
|
513
|
+
touch: request.touch ?? preset.hasTouch ?? false,
|
|
523
514
|
userAgent: request.userAgent ?? device.userAgent ?? null,
|
|
524
515
|
since: new Date().toISOString(),
|
|
525
516
|
};
|
|
@@ -675,11 +666,17 @@ export class BrowserSession {
|
|
|
675
666
|
}
|
|
676
667
|
/**
|
|
677
668
|
* Click an element the way a person does: scrolled into view, then a mouse
|
|
678
|
-
* press and release at its centre, dispatched by the browser.
|
|
669
|
+
* press and release at its centre, dispatched by the browser. Under touch
|
|
670
|
+
* emulation it is a tap instead: Chrome makes the touchstart, touchend,
|
|
671
|
+
* mousedown, mouseup and click from it, as on a phone.
|
|
679
672
|
*
|
|
680
673
|
* Not `element.click()`: that event is untrusted, and a consent banner or an
|
|
681
674
|
* add-to-cart handler that checks `isTrusted` ignores it — which is exactly
|
|
682
675
|
* the tracking this exists to verify.
|
|
676
|
+
*
|
|
677
|
+
* Not a mouse press under touch emulation: `--device` turns on
|
|
678
|
+
* `Emulation.setEmitTouchEventsForMouse`, and Chrome then never answers
|
|
679
|
+
* `Input.dispatchMouseEvent` for the press.
|
|
683
680
|
*/
|
|
684
681
|
async click(target) {
|
|
685
682
|
this.require();
|
|
@@ -689,21 +686,38 @@ export class BrowserSession {
|
|
|
689
686
|
const x = Math.round(box.x + box.width / 2);
|
|
690
687
|
const y = Math.round(box.y + box.height / 2);
|
|
691
688
|
const before = this.url();
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
689
|
+
// The state of `browser emulate` wins over the run's `--device`: it is the later one.
|
|
690
|
+
const input = (this.emulation?.state.touch ?? this.context?.touch) ? "touch" : "mouse";
|
|
691
|
+
if (input === "touch") {
|
|
692
|
+
// The tap of the ux-report journeys: a finger held for 60 ms.
|
|
693
|
+
await this.send("Input.dispatchTouchEvent", {
|
|
694
|
+
type: "touchStart",
|
|
695
|
+
touchPoints: [{ x, y, radiusX: 4, radiusY: 4, force: 1, id: 1 }],
|
|
696
|
+
});
|
|
697
|
+
await new Promise((resolve) => setTimeout(resolve, 60));
|
|
698
|
+
await this.send("Input.dispatchTouchEvent", {
|
|
699
|
+
type: "touchEnd",
|
|
700
|
+
touchPoints: [],
|
|
699
701
|
});
|
|
700
702
|
}
|
|
703
|
+
else {
|
|
704
|
+
for (const type of ["mouseMoved", "mousePressed", "mouseReleased"]) {
|
|
705
|
+
await this.send("Input.dispatchMouseEvent", {
|
|
706
|
+
type,
|
|
707
|
+
x,
|
|
708
|
+
y,
|
|
709
|
+
button: type === "mouseMoved" ? "none" : "left",
|
|
710
|
+
clickCount: type === "mouseMoved" ? 0 : 1,
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
701
714
|
const { node } = await this.send("DOM.describeNode", { nodeId }).catch(() => ({ node: undefined }));
|
|
702
715
|
return {
|
|
703
716
|
url: this.url(),
|
|
704
|
-
did:
|
|
717
|
+
did: `${input === "touch" ? "tapped" : "clicked"} ${target.selector ?? `"${target.text}"`} at ${x},${y}`,
|
|
705
718
|
element: node ? describeNode(node) : null,
|
|
706
719
|
at: { x, y },
|
|
720
|
+
input,
|
|
707
721
|
urlBefore: before,
|
|
708
722
|
};
|
|
709
723
|
}
|
|
@@ -800,11 +814,12 @@ export class BrowserSession {
|
|
|
800
814
|
mobile: state.mobile,
|
|
801
815
|
screenWidth: state.width,
|
|
802
816
|
screenHeight: state.height,
|
|
817
|
+
screenOrientation: state.width > state.height
|
|
818
|
+
? { type: "landscapePrimary", angle: 90 }
|
|
819
|
+
: { type: "portraitPrimary", angle: 0 },
|
|
803
820
|
});
|
|
804
|
-
await send
|
|
805
|
-
|
|
806
|
-
...(state.touch ? { maxTouchPoints: 5 } : {}),
|
|
807
|
-
});
|
|
821
|
+
await setTouch(send, state.touch);
|
|
822
|
+
await this.context?.setDeviceTouch?.(state.touch);
|
|
808
823
|
if (state.userAgent) {
|
|
809
824
|
await send("Emulation.setUserAgentOverride", {
|
|
810
825
|
userAgent: state.userAgent,
|
|
@@ -820,8 +835,13 @@ export class BrowserSession {
|
|
|
820
835
|
return;
|
|
821
836
|
}
|
|
822
837
|
const send = (method, params = {}) => bounded(session.send(method, params), method, this.cdpAnswerMs).catch(() => undefined);
|
|
823
|
-
|
|
824
|
-
|
|
838
|
+
// Back to the start, not to bare Chrome: the page shares one screen and one touch state with `--device`.
|
|
839
|
+
const start = this.context?.deviceMetrics;
|
|
840
|
+
await (start
|
|
841
|
+
? send("Emulation.setDeviceMetricsOverride", start)
|
|
842
|
+
: send("Emulation.clearDeviceMetricsOverride"));
|
|
843
|
+
await setTouch(send, this.context?.touch === true);
|
|
844
|
+
await this.context?.setDeviceTouch?.(this.context.touch === true);
|
|
825
845
|
// An empty user agent is CDP's way of saying "no override".
|
|
826
846
|
await send("Emulation.setUserAgentOverride", { userAgent: "" });
|
|
827
847
|
}
|
|
@@ -1298,3 +1318,20 @@ function timeout(ms, expression) {
|
|
|
1298
1318
|
timer.unref();
|
|
1299
1319
|
});
|
|
1300
1320
|
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Switch touch emulation and Chrome's mouse-to-touch translation together.
|
|
1323
|
+
*
|
|
1324
|
+
* `--device` turns the translation on for a touch device. Left on under a
|
|
1325
|
+
* desktop emulation, it swallows the mouse press of `click`, which then never
|
|
1326
|
+
* gets an answer.
|
|
1327
|
+
*/
|
|
1328
|
+
async function setTouch(send, touch) {
|
|
1329
|
+
await send("Emulation.setTouchEmulationEnabled", {
|
|
1330
|
+
enabled: touch,
|
|
1331
|
+
...(touch ? { maxTouchPoints: 5 } : {}),
|
|
1332
|
+
});
|
|
1333
|
+
await send("Emulation.setEmitTouchEventsForMouse", {
|
|
1334
|
+
enabled: touch,
|
|
1335
|
+
configuration: "mobile",
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
@@ -1233,6 +1233,8 @@ export interface BrowserClickData extends BrowserActionData {
|
|
|
1233
1233
|
x: number;
|
|
1234
1234
|
y: number;
|
|
1235
1235
|
};
|
|
1236
|
+
/** A tap under touch emulation, else a mouse press and release. */
|
|
1237
|
+
input: "touch" | "mouse";
|
|
1236
1238
|
/** The page before the click, so a navigation it caused reads as one. */
|
|
1237
1239
|
urlBefore: string | null;
|
|
1238
1240
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { CDPSession
|
|
1
|
+
import { CDPSession } from "puppeteer";
|
|
2
2
|
import { Protocol } from "puppeteer-core";
|
|
3
3
|
import { AbortResponse } from "./browser/abort-response.js";
|
|
4
4
|
import { task } from "./todo-collector.js";
|
|
5
5
|
import { VanillaPuppeteer } from "puppeteer-extra";
|
|
6
6
|
import { ChromeFeatureFinding, ChromeFlagDuplicate } from "../../helpers/chrome-flags.js";
|
|
7
7
|
import { CliEnvironment } from "../cli/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { FetchDevice, OnboardingDeviceEmulation } from "../browser-fetch/device-emulation.js";
|
|
9
9
|
export declare const HEADLESS_PARITY_ARGS: string[];
|
|
10
10
|
declare const HEADLESS_DEFAULT_ARGS_TO_DROP: string[];
|
|
11
11
|
export { HEADLESS_DEFAULT_ARGS_TO_DROP };
|
|
12
|
-
/**
|
|
13
|
-
export
|
|
14
|
-
viewport: Viewport;
|
|
15
|
-
};
|
|
12
|
+
/** What Chrome reports for a touchscreen phone or tablet. */
|
|
13
|
+
export declare const MAX_TOUCH_POINTS = 5;
|
|
16
14
|
export declare const BROWSER_EVENTS: {
|
|
17
15
|
DISCONNECTED: string;
|
|
18
16
|
FETCH_AUTH_REQUIRED: string;
|
|
@@ -55,7 +53,12 @@ export declare class BrowserContext {
|
|
|
55
53
|
readonly browserArgs: string[];
|
|
56
54
|
readonly chromePath: string;
|
|
57
55
|
/** The device of `--device`, or undefined to leave Chrome as it launches. */
|
|
58
|
-
readonly emulation?:
|
|
56
|
+
readonly emulation?: OnboardingDeviceEmulation;
|
|
57
|
+
/**
|
|
58
|
+
* Switches the touch of `--device` on every page, set by `emulateDevice`. Only the CDP session
|
|
59
|
+
* that turned Chrome's mouse-to-touch translation on can keep it off across a navigation.
|
|
60
|
+
*/
|
|
61
|
+
setDeviceTouch?: (touch: boolean) => Promise<void>;
|
|
59
62
|
constructor(domain: string, browserVersionString?: string, chromeFlags?: string[], environment?: CliEnvironment, userAgent?: string, debuggingPort?: boolean, headless?: boolean, debugPort?: number, device?: FetchDevice);
|
|
60
63
|
/**
|
|
61
64
|
* The user agent is a launch flag rather than only a CDP override on purpose: a per-page
|
|
@@ -3,7 +3,7 @@ import { buildHeadedUserAgent } from "./browser/executable/headed-user-agent.js"
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { defaultArgs } from "puppeteer";
|
|
5
5
|
import { findChromeFeatureFindings, findDuplicateChromeFlags, isFeatureListFlag, mergeChromeFeatureFlags, } from "../../helpers/chrome-flags.js";
|
|
6
|
-
import {
|
|
6
|
+
import { onboardingDeviceEmulation, } from "../browser-fetch/device-emulation.js";
|
|
7
7
|
const DEFAULT_BROWSER_ARGS = [
|
|
8
8
|
// No `Translate`: Chrome's translate code has no feature of that name, and Puppeteer disables it anyway.
|
|
9
9
|
"--enable-features=NetworkService",
|
|
@@ -37,12 +37,10 @@ const HEADLESS_DEFAULT_ARGS_TO_DROP = [
|
|
|
37
37
|
"--hide-scrollbars",
|
|
38
38
|
];
|
|
39
39
|
export { HEADLESS_DEFAULT_ARGS_TO_DROP };
|
|
40
|
-
/** `--device desktop` presents Chrome on Windows, the most common Chrome desktop in RUM (60%). */
|
|
41
|
-
const DESKTOP_PLATFORM = "win32";
|
|
42
40
|
/** Room next to an emulated viewport for the DevTools panel that `devtools: true` docks in headed mode. */
|
|
43
41
|
const DEVTOOLS_GUTTER = 520;
|
|
44
42
|
/** What Chrome reports for a touchscreen phone or tablet. */
|
|
45
|
-
const MAX_TOUCH_POINTS = 5;
|
|
43
|
+
export const MAX_TOUCH_POINTS = 5;
|
|
46
44
|
export const BROWSER_EVENTS = {
|
|
47
45
|
DISCONNECTED: "disconnected",
|
|
48
46
|
FETCH_AUTH_REQUIRED: "Fetch.authRequired",
|
|
@@ -86,6 +84,11 @@ export class BrowserContext {
|
|
|
86
84
|
chromePath;
|
|
87
85
|
/** The device of `--device`, or undefined to leave Chrome as it launches. */
|
|
88
86
|
emulation;
|
|
87
|
+
/**
|
|
88
|
+
* Switches the touch of `--device` on every page, set by `emulateDevice`. Only the CDP session
|
|
89
|
+
* that turned Chrome's mouse-to-touch translation on can keep it off across a navigation.
|
|
90
|
+
*/
|
|
91
|
+
setDeviceTouch;
|
|
89
92
|
constructor(domain, browserVersionString = "unknown", chromeFlags, environment, userAgent, debuggingPort = false, headless = false, debugPort = 9222, device) {
|
|
90
93
|
this.domain = domain;
|
|
91
94
|
this.browserVersionString = browserVersionString;
|
|
@@ -110,10 +113,7 @@ export class BrowserContext {
|
|
|
110
113
|
browserArguments.push(`--user-data-dir=${temporaryProfileDirectory}`);
|
|
111
114
|
}
|
|
112
115
|
if (device) {
|
|
113
|
-
this.emulation =
|
|
114
|
-
...deviceEmulation(browserVersionString, device, DESKTOP_PLATFORM),
|
|
115
|
-
viewport: DEVICE_VIEWPORTS[device],
|
|
116
|
-
};
|
|
116
|
+
this.emulation = onboardingDeviceEmulation(browserVersionString, device);
|
|
117
117
|
}
|
|
118
118
|
this.userAgent ??=
|
|
119
119
|
this.emulation?.userAgent ??
|
|
@@ -87,6 +87,9 @@ export class OnboardingService {
|
|
|
87
87
|
reportAgentActivity: (label, breakpoints, releasedAt) => this.reportAgentActivity(label, breakpoints, releasedAt),
|
|
88
88
|
extensionArms: () => this.extensionBridge.available,
|
|
89
89
|
devtoolsExtensionId: () => this.extensionBridge.devtoolsExtensionId,
|
|
90
|
+
touch: this.browserContext.getTouchEmulation()?.enabled === true,
|
|
91
|
+
deviceMetrics: this.browserContext.getDeviceMetricsOverride(),
|
|
92
|
+
setDeviceTouch: async (touch) => this.browserContext.setDeviceTouch?.(touch),
|
|
90
93
|
});
|
|
91
94
|
this.cli.successAction("ONBOARDING:PREPARE:BROWSER", undefined, {
|
|
92
95
|
scope: "browser",
|
|
@@ -2,6 +2,8 @@ import { expect } from "chai";
|
|
|
2
2
|
import { describe, it } from "mocha";
|
|
3
3
|
import { BadUrlError, CdpRefusedError, NoSuchTabError, BrowserSession, CdpTimeoutError, NoBrowserError, NoPageError, PagePausedError, } from "../../control/browser-session.js";
|
|
4
4
|
import { ServiceWorkerTracker } from "../../control/service-worker-tracker.js";
|
|
5
|
+
import { BrowserContext } from "../../onboarding-model.js";
|
|
6
|
+
import { FETCH_DEVICES } from "../../../browser-fetch/device-emulation.js";
|
|
5
7
|
/** One app, two brand domains, started on the first. */
|
|
6
8
|
const BASE = "https://brand-a.example";
|
|
7
9
|
const SIBLING = "https://brand-b.example";
|
|
@@ -12,7 +14,9 @@ const SIBLING = "https://brand-b.example";
|
|
|
12
14
|
* call, because what these two ops get wrong is not whether they act but which
|
|
13
15
|
* origin they act on.
|
|
14
16
|
*/
|
|
15
|
-
function attached(at, origins = [BASE, SIBLING], browser = {}
|
|
17
|
+
function attached(at, origins = [BASE, SIBLING], browser = {},
|
|
18
|
+
/** More of the run context, such as the `--device` it started with. */
|
|
19
|
+
context = {}) {
|
|
16
20
|
const calls = [];
|
|
17
21
|
const goto = [];
|
|
18
22
|
let current = at;
|
|
@@ -40,6 +44,7 @@ function attached(at, origins = [BASE, SIBLING], browser = {}) {
|
|
|
40
44
|
origins,
|
|
41
45
|
reinstall: async () => undefined,
|
|
42
46
|
serviceWorkers: new ServiceWorkerTracker(),
|
|
47
|
+
...context,
|
|
43
48
|
});
|
|
44
49
|
return {
|
|
45
50
|
session,
|
|
@@ -504,7 +509,7 @@ describe("BrowserSession", () => {
|
|
|
504
509
|
reload: false,
|
|
505
510
|
});
|
|
506
511
|
expect(data.emulation).to.include({
|
|
507
|
-
width:
|
|
512
|
+
width: 1280,
|
|
508
513
|
userAgent: safari,
|
|
509
514
|
touch: false,
|
|
510
515
|
});
|
|
@@ -513,15 +518,78 @@ describe("BrowserSession", () => {
|
|
|
513
518
|
});
|
|
514
519
|
expect(paramsOf(calls, "Emulation.setTouchEmulationEnabled")).to.deep.equal({ enabled: false });
|
|
515
520
|
});
|
|
521
|
+
for (const device of FETCH_DEVICES) {
|
|
522
|
+
it(`should present ${device} exactly as --device ${device} does`, async () => {
|
|
523
|
+
const browser = withWorkers([]).browser;
|
|
524
|
+
const { session, calls } = attached(`${BASE}/`, [BASE], browser);
|
|
525
|
+
const start = new BrowserContext("example.com", await browser.version(), [], {
|
|
526
|
+
settings: {
|
|
527
|
+
chromePath: "/usr/bin/google-chrome",
|
|
528
|
+
chromeUserProfilePath: "/tmp/sk-test-profile",
|
|
529
|
+
},
|
|
530
|
+
}, undefined, false, false, 9222, device);
|
|
531
|
+
await session.emulate({ device, reload: false });
|
|
532
|
+
expect(paramsOf(calls, "Emulation.setUserAgentOverride")).to.deep.equal({
|
|
533
|
+
userAgent: start.emulation?.userAgent,
|
|
534
|
+
userAgentMetadata: start.emulation?.metadata,
|
|
535
|
+
});
|
|
536
|
+
expect(paramsOf(calls, "Emulation.setDeviceMetricsOverride")).to.deep.equal(start.getDeviceMetricsOverride());
|
|
537
|
+
expect(paramsOf(calls, "Emulation.setTouchEmulationEnabled")).to.deep.equal(start.getTouchEmulation());
|
|
538
|
+
expect(paramsOf(calls, "Emulation.setEmitTouchEventsForMouse")).to.deep.equal({
|
|
539
|
+
enabled: start.getTouchEmulation()?.enabled,
|
|
540
|
+
configuration: "mobile",
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
it("should switch mouse-to-touch off for the desktop of a touch run", async () => {
|
|
545
|
+
const browser = withWorkers([]).browser;
|
|
546
|
+
const deviceTouch = [];
|
|
547
|
+
const { session, calls } = attached(`${BASE}/`, [BASE], browser, {
|
|
548
|
+
touch: true,
|
|
549
|
+
setDeviceTouch: async (touch) => {
|
|
550
|
+
deviceTouch.push(touch);
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
await session.emulate({ device: "desktop", reload: false });
|
|
554
|
+
// The --device session re-applies its own touch on every navigation, so it must switch too.
|
|
555
|
+
expect(deviceTouch).to.deep.equal([false]);
|
|
556
|
+
expect(paramsOf(calls, "Emulation.setEmitTouchEventsForMouse")).to.deep.equal({ enabled: false, configuration: "mobile" });
|
|
557
|
+
expect(paramsOf(calls, "Emulation.setTouchEmulationEnabled")).to.deep.equal({ enabled: false });
|
|
558
|
+
});
|
|
559
|
+
it("should put the --device screen and touch back on off", async () => {
|
|
560
|
+
const browser = withWorkers([]).browser;
|
|
561
|
+
const deviceMetrics = {
|
|
562
|
+
width: 384,
|
|
563
|
+
height: 832,
|
|
564
|
+
deviceScaleFactor: 2.8125,
|
|
565
|
+
mobile: true,
|
|
566
|
+
};
|
|
567
|
+
const deviceTouch = [];
|
|
568
|
+
const { session, calls } = attached(`${BASE}/`, [BASE], browser, {
|
|
569
|
+
touch: true,
|
|
570
|
+
deviceMetrics,
|
|
571
|
+
setDeviceTouch: async (touch) => {
|
|
572
|
+
deviceTouch.push(touch);
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
await session.emulate({ device: "desktop", reload: false });
|
|
576
|
+
calls.length = 0;
|
|
577
|
+
await session.emulate({ device: "off", reload: false });
|
|
578
|
+
expect(deviceTouch).to.deep.equal([false, true]);
|
|
579
|
+
expect(calls.map((call) => call.method)).not.to.include("Emulation.clearDeviceMetricsOverride");
|
|
580
|
+
expect(paramsOf(calls, "Emulation.setDeviceMetricsOverride")).to.deep.equal(deviceMetrics);
|
|
581
|
+
expect(paramsOf(calls, "Emulation.setTouchEmulationEnabled")).to.deep.equal({ enabled: true, maxTouchPoints: 5 });
|
|
582
|
+
expect(paramsOf(calls, "Emulation.setEmitTouchEventsForMouse")).to.deep.equal({ enabled: true, configuration: "mobile" });
|
|
583
|
+
});
|
|
516
584
|
it("should emulate a device on the page, and keep it across a new session", async () => {
|
|
517
585
|
const browser = withWorkers([]).browser;
|
|
518
586
|
const { session, calls, detachCdp } = attached(`${BASE}/`, [BASE, SIBLING], browser);
|
|
519
587
|
const data = await session.emulate({ device: "mobile", reload: false });
|
|
520
588
|
const metrics = () => calls.filter((call) => call.method === "Emulation.setDeviceMetricsOverride");
|
|
521
589
|
expect(metrics()[0].params).to.include({
|
|
522
|
-
width:
|
|
523
|
-
height:
|
|
524
|
-
deviceScaleFactor:
|
|
590
|
+
width: 384,
|
|
591
|
+
height: 832,
|
|
592
|
+
deviceScaleFactor: 2.8125,
|
|
525
593
|
mobile: true,
|
|
526
594
|
});
|
|
527
595
|
expect(data.emulation?.userAgent).to.contain("Mobile");
|
|
@@ -545,7 +613,9 @@ describe("BrowserSession", () => {
|
|
|
545
613
|
send: async (method, params = {}) => {
|
|
546
614
|
calls.push(method === "Input.dispatchMouseEvent"
|
|
547
615
|
? `${method}:${params.type}@${params.x},${params.y}`
|
|
548
|
-
: method
|
|
616
|
+
: method === "Input.dispatchTouchEvent"
|
|
617
|
+
? `${method}:${params.type}@${JSON.stringify(params.touchPoints)}`
|
|
618
|
+
: method);
|
|
549
619
|
switch (method) {
|
|
550
620
|
case "Runtime.evaluate":
|
|
551
621
|
return new Promise(() => undefined);
|
|
@@ -605,11 +675,14 @@ describe("BrowserSession", () => {
|
|
|
605
675
|
target: () => ({ createCDPSession: async () => cdp }),
|
|
606
676
|
};
|
|
607
677
|
const session = new BrowserSession(200);
|
|
608
|
-
|
|
678
|
+
// No version, so no user agent: `emulate` sets only the page's metrics and touch.
|
|
679
|
+
const browser = { version: async () => "", targets: () => [] };
|
|
680
|
+
session.attach(browser, page, {
|
|
609
681
|
origin: BASE,
|
|
610
682
|
origins: [BASE],
|
|
611
683
|
reinstall: async () => undefined,
|
|
612
684
|
serviceWorkers: new ServiceWorkerTracker(),
|
|
685
|
+
touch: options.touch,
|
|
613
686
|
});
|
|
614
687
|
return { session, calls };
|
|
615
688
|
};
|
|
@@ -632,6 +705,35 @@ describe("BrowserSession", () => {
|
|
|
632
705
|
"Input.dispatchMouseEvent:mouseReleased@60,45",
|
|
633
706
|
]);
|
|
634
707
|
expect(data.element).to.equal("button#buy");
|
|
708
|
+
expect(data.input).to.equal("mouse");
|
|
709
|
+
});
|
|
710
|
+
it("should tap, not press a mouse, under touch emulation", async () => {
|
|
711
|
+
// With --device mobile Chrome never answers a mouse press: CDP_TIMEOUT.
|
|
712
|
+
const { session, calls } = paused({ touch: true });
|
|
713
|
+
const data = await session.click({ selector: "#buy" });
|
|
714
|
+
expect(calls).to.include.members([
|
|
715
|
+
`Input.dispatchTouchEvent:touchStart@[{"x":60,"y":45,"radiusX":4,"radiusY":4,"force":1,"id":1}]`,
|
|
716
|
+
"Input.dispatchTouchEvent:touchEnd@[]",
|
|
717
|
+
]);
|
|
718
|
+
expect(calls.filter((call) => call.startsWith("Input.dispatchMouseEvent"))).to.deep.equal([]);
|
|
719
|
+
expect(data.input).to.equal("touch");
|
|
720
|
+
expect(data.did).to.match(/^tapped #buy/);
|
|
721
|
+
});
|
|
722
|
+
it("should click and tap as the device of `emulate` says, not as --device did", async () => {
|
|
723
|
+
const { session, calls } = paused({ touch: true });
|
|
724
|
+
const presses = () => calls.filter((call) => call.startsWith("Input.dispatch"));
|
|
725
|
+
await session.emulate({ device: "desktop", reload: false });
|
|
726
|
+
const clicked = await session.click({ selector: "#buy" });
|
|
727
|
+
expect(clicked.input).to.equal("mouse");
|
|
728
|
+
expect(presses()).to.include("Input.dispatchMouseEvent:mousePressed@60,45");
|
|
729
|
+
calls.length = 0;
|
|
730
|
+
await session.emulate({ device: "mobile", reload: false });
|
|
731
|
+
const tapped = await session.click({ selector: "#buy" });
|
|
732
|
+
expect(tapped.input).to.equal("touch");
|
|
733
|
+
expect(presses()).to.deep.equal([
|
|
734
|
+
`Input.dispatchTouchEvent:touchStart@[{"x":60,"y":45,"radiusX":4,"radiusY":4,"force":1,"id":1}]`,
|
|
735
|
+
"Input.dispatchTouchEvent:touchEnd@[]",
|
|
736
|
+
]);
|
|
635
737
|
});
|
|
636
738
|
it("should find an element inside Speed Kit's SSR shadow root", async () => {
|
|
637
739
|
// At BP3 the page's h1 exists only inside SK-SHADOW-APP-ROOT, and a
|
|
@@ -28,7 +28,7 @@ export const BrowserEmulateBuildContext = pageControlContext({
|
|
|
28
28
|
name: "device",
|
|
29
29
|
required: true,
|
|
30
30
|
options: ["mobile", "tablet", "desktop", "off"],
|
|
31
|
-
description: "
|
|
31
|
+
description: "The same profile as sk onboarding --device: screen, DPR, user agent, client hints and touch. off puts back the state the run started with",
|
|
32
32
|
}),
|
|
33
33
|
}, {
|
|
34
34
|
width: Flags.integer({ description: "Override the preset's width" }),
|
package/oclif.manifest.json
CHANGED
|
@@ -2965,7 +2965,7 @@
|
|
|
2965
2965
|
"required": false
|
|
2966
2966
|
}
|
|
2967
2967
|
},
|
|
2968
|
-
"description": "Click an element the way a visitor does — a trusted
|
|
2968
|
+
"description": "Click an element the way a visitor does — a trusted click at its centre, a tap under touch emulation — by selector or by its text",
|
|
2969
2969
|
"examples": [
|
|
2970
2970
|
"$ sk onboarding browser click '#onetrust-accept-btn-handler'",
|
|
2971
2971
|
"$ sk onboarding browser click --text 'In den Warenkorb'",
|
|
@@ -3027,7 +3027,7 @@
|
|
|
3027
3027
|
"aliases": [],
|
|
3028
3028
|
"args": {
|
|
3029
3029
|
"device": {
|
|
3030
|
-
"description": "
|
|
3030
|
+
"description": "The same profile as sk onboarding --device: screen, DPR, user agent, client hints and touch. off puts back the state the run started with",
|
|
3031
3031
|
"name": "device",
|
|
3032
3032
|
"options": [
|
|
3033
3033
|
"mobile",
|
|
@@ -5234,5 +5234,5 @@
|
|
|
5234
5234
|
]
|
|
5235
5235
|
}
|
|
5236
5236
|
},
|
|
5237
|
-
"version": "4.51.0-run-control.
|
|
5237
|
+
"version": "4.51.0-run-control.5"
|
|
5238
5238
|
}
|