@speedkit/cli 4.48.0 → 4.50.1
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/CHANGELOG.md +24 -0
- package/README.md +8 -1
- package/dist/commands/onboarding.d.ts +2 -0
- package/dist/commands/onboarding.js +1 -0
- package/dist/services/browser-fetch/device-emulation.d.ts +16 -3
- package/dist/services/browser-fetch/device-emulation.js +32 -17
- package/dist/services/browser-fetch/spec/device-emulation.spec.js +20 -0
- package/dist/services/diff/diff-service-factory.js +1 -1
- package/dist/services/diff/spec/page-source.spec.js +1 -1
- package/dist/services/onboarding/browser/emulate-device.d.ts +13 -0
- package/dist/services/onboarding/browser/emulate-device.js +50 -0
- package/dist/services/onboarding/browser/launch-browser.js +7 -2
- package/dist/services/onboarding/onboarding-model.d.ts +27 -6
- package/dist/services/onboarding/onboarding-model.js +88 -15
- package/dist/services/onboarding/onboarding-service-build-context.d.ts +7 -0
- package/dist/services/onboarding/onboarding-service-build-context.js +12 -0
- package/dist/services/onboarding/onboarding-service-factory.js +5 -1
- package/dist/services/onboarding/spec/onboarding-model.spec.js +93 -2
- package/dist/services/onboarding/spec/onboarding-service-build-context.spec.js +16 -1
- package/dist/services/origin-request/asset-variations.d.ts +24 -3
- package/dist/services/origin-request/asset-variations.js +51 -17
- package/dist/services/origin-request/origin-fetcher.d.ts +2 -2
- package/dist/services/origin-request/origin-fetcher.js +10 -4
- package/dist/services/origin-request/origin-request-service-factory.js +1 -1
- package/dist/services/origin-request/origin-request-service.d.ts +6 -2
- package/dist/services/origin-request/origin-request-service.js +32 -11
- package/dist/services/origin-request/runtime-config-source.d.ts +3 -1
- package/dist/services/origin-request/runtime-config-source.js +1 -0
- package/dist/services/origin-request/spec/asset-variations.spec.js +58 -0
- package/dist/services/origin-request/spec/origin-fetcher.spec.js +16 -1
- package/dist/services/origin-request/spec/origin-request-service.spec.js +27 -1
- package/dist/services/origin-request/spec/runtime-config-source.spec.d.ts +1 -0
- package/dist/services/origin-request/spec/runtime-config-source.spec.js +47 -0
- package/oclif.manifest.json +167 -144
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [4.50.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.50.0...v4.50.1) (2026-10-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **onboarding:** drop the --device warning about device detection ([e7325a6](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/e7325a6bea67b5ba502a0cda5943b28048372411))
|
|
7
|
+
|
|
8
|
+
# [4.50.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.49.0...v4.50.0) (2026-10-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **origin-request:** apply the runtime config's origin map to origin fetches ([dfc6f63](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/dfc6f6340033cce1525e7c25a159e8b7654d492b))
|
|
14
|
+
* **origin-request:** hide origin map header values in the report ([65c161a](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/65c161a973d95e3559e46ae7b1c42b8dbd697a5e))
|
|
15
|
+
|
|
16
|
+
# [4.49.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.48.0...v4.49.0) (2026-10-26)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* **onboarding:** emulate a whole device with --device mobile|tablet|desktop ([7f978e7](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/7f978e7aaf356952825c185e3e13f29f74dba26f))
|
|
22
|
+
* **onboarding:** implement mobileMode ([64aed4f](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/64aed4fc6059db54c084fb1e8459038bf574acc6))
|
|
23
|
+
* **onboarding:** take the --device presets from Speed Kit RUM ([aad8b6d](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/aad8b6d890d31622417710b500ead09e83f719d3))
|
|
24
|
+
|
|
1
25
|
# [4.48.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.47.0...v4.48.0) (2026-10-19)
|
|
2
26
|
|
|
3
27
|
|
package/README.md
CHANGED
|
@@ -784,7 +784,8 @@ Start a local dev environment for building and testing the Speed Kit configurati
|
|
|
784
784
|
```
|
|
785
785
|
USAGE
|
|
786
786
|
$ sk onboarding [CUSTOMERPATH] [-c <value>] [-t] [-d <value>] [-p] [--debugPort <value>] [-v] [-s]
|
|
787
|
-
[--headless] [--app <value> [--inject [<installationId>] | --browse]]
|
|
787
|
+
[--headless] [-m | --device mobile|tablet|desktop] [--app <value> [--inject [<installationId>] | --browse]]
|
|
788
|
+
[--browserFetch]
|
|
788
789
|
|
|
789
790
|
ARGUMENTS
|
|
790
791
|
[CUSTOMERPATH] The customer config path (optional with --browse and --inject)
|
|
@@ -792,6 +793,7 @@ ARGUMENTS
|
|
|
792
793
|
FLAGS
|
|
793
794
|
-c, --configName=<value> [default: production] The costumer config name
|
|
794
795
|
-d, --domain=<value> Startup domain (optional)
|
|
796
|
+
-m, --mobile Same as --device mobile
|
|
795
797
|
-p, --debuggingPort Enable remote debugging port (disables speculation rules/prerendering)
|
|
796
798
|
-s, --ignoreContentSecurityPolicy Removes header/meta "content-security-policy" for origin-responses
|
|
797
799
|
-t, --useTestConfig Override app with configured testApp
|
|
@@ -806,6 +808,9 @@ FLAGS
|
|
|
806
808
|
otherwise detected and rerouted on its own.
|
|
807
809
|
--debugPort=<value> [default: 9222] Chrome remote debugging port (only used with -p/--headless). Use
|
|
808
810
|
distinct ports to run multiple onboarding processes at once.
|
|
811
|
+
--device=<option> Emulate a device in every page and Service Worker: user agent, client hints,
|
|
812
|
+
viewport, pointer and touch. Without it, Chrome runs as it launches.
|
|
813
|
+
<options: mobile|tablet|desktop>
|
|
809
814
|
--headless Run Chrome in headless mode (for CI environments). Implicitly enables remote
|
|
810
815
|
debugging port.
|
|
811
816
|
--inject=[<installationId>] Inject a deployed Speed Kit installation into the site, for a customer that has not
|
|
@@ -825,6 +830,8 @@ EXAMPLES
|
|
|
825
830
|
|
|
826
831
|
$ sk onboarding customers/decathlon.de --browse -p
|
|
827
832
|
|
|
833
|
+
$ sk onboarding customers/decathlon.de -p --device tablet
|
|
834
|
+
|
|
828
835
|
$ sk onboarding customers/decathlon.de --inject
|
|
829
836
|
|
|
830
837
|
$ sk onboarding customers/decathlon.de --inject <installationId>
|
|
@@ -16,6 +16,8 @@ export default class Onboarding extends SkCommand<OnboardingServiceBuildContext>
|
|
|
16
16
|
verboseLevel: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
17
|
ignoreContentSecurityPolicy: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
18
|
headless: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
device: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
mobile: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
21
|
browse: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
22
|
inject: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
23
|
app: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -10,6 +10,7 @@ export default class Onboarding extends SkCommand {
|
|
|
10
10
|
`$ sk onboarding customers/decathlon.de -c production -d www.decathlon.de`,
|
|
11
11
|
`$ sk onboarding --browse -d www.decathlon.de --headless --debugPort 9290`,
|
|
12
12
|
`$ sk onboarding customers/decathlon.de --browse -p`,
|
|
13
|
+
`$ sk onboarding customers/decathlon.de -p --device tablet`,
|
|
13
14
|
`$ sk onboarding customers/decathlon.de --inject`,
|
|
14
15
|
`$ sk onboarding customers/decathlon.de --inject <installationId>`,
|
|
15
16
|
];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Protocol, Viewport } from "puppeteer";
|
|
2
|
-
/** The devices the browser fetcher can present, one per Speed Kit device variation. */
|
|
3
|
-
export
|
|
2
|
+
/** The devices the browser fetcher and `sk onboarding --device` can present, one per Speed Kit device variation. */
|
|
3
|
+
export declare const FETCH_DEVICES: readonly ["mobile", "tablet", "desktop"];
|
|
4
|
+
export type FetchDevice = (typeof FETCH_DEVICES)[number];
|
|
4
5
|
/** Everything a page needs to look like one device, as `openPage` applies it. */
|
|
5
6
|
export interface DeviceEmulation {
|
|
6
7
|
readonly device: FetchDevice;
|
|
@@ -14,6 +15,16 @@ export interface DeviceEmulation {
|
|
|
14
15
|
/** Null leaves the window's own viewport in place, which is what a desktop fetch wants. */
|
|
15
16
|
readonly viewport: Viewport | null;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The most common Chrome screen per device in Speed Kit RUM, in CSS px (physical px / DPR).
|
|
20
|
+
* Source: `rum.pi`, all apps, real page impressions with browser Chrome, snapshot of 2026-10-25.
|
|
21
|
+
* Refresh the values from the same query.
|
|
22
|
+
*
|
|
23
|
+
* - mobile: 1080x2340 @2.8125, the top Android Chrome phone screen (15.8%).
|
|
24
|
+
* - tablet: 1920x1200 @1.5, the top Android Chrome tablet screen (16.6% landscape, 16.4% portrait).
|
|
25
|
+
* - desktop: 1920x1080 @1, the top Chrome desktop screen (21%).
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEVICE_VIEWPORTS: Record<FetchDevice, Viewport>;
|
|
17
28
|
/** True for one of the user agents the Asset API sends for a device variation. */
|
|
18
29
|
export declare function isSpeedKitUserAgent(userAgent?: string): boolean;
|
|
19
30
|
/**
|
|
@@ -42,5 +53,7 @@ export declare function deviceForUserAgent(userAgent?: string): FetchDevice | un
|
|
|
42
53
|
*
|
|
43
54
|
* @param browserVersionString - `browser.version()`, e.g. `Chrome/146.0.7680.165`.
|
|
44
55
|
* @param device - The device to present.
|
|
56
|
+
* @param platform - Node platform of the desktop user agent. The fetcher keeps the host's, so its
|
|
57
|
+
* fingerprint matches; `sk onboarding --device desktop` presents Windows.
|
|
45
58
|
*/
|
|
46
|
-
export declare function deviceEmulation(browserVersionString: string, device: FetchDevice): DeviceEmulation;
|
|
59
|
+
export declare function deviceEmulation(browserVersionString: string, device: FetchDevice, platform?: string): DeviceEmulation;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { buildHeadedUserAgent, chromeMajorVersion, } from "../onboarding/browser/executable/headed-user-agent.js";
|
|
2
2
|
import { DEFAULT_USER_AGENT, MOBILE_USER_AGENT, TABLET_USER_AGENT, } from "../origin-request/asset-variations.js";
|
|
3
|
+
/** The devices the browser fetcher and `sk onboarding --device` can present, one per Speed Kit device variation. */
|
|
4
|
+
export const FETCH_DEVICES = ["mobile", "tablet", "desktop"];
|
|
3
5
|
/**
|
|
4
6
|
* Android's frozen platform token. Chrome's UA reduction pins every Android build to
|
|
5
7
|
* `Android 10; K` regardless of the device, so this is the literal string real Chrome sends —
|
|
@@ -30,28 +32,38 @@ const DEFAULT_DESKTOP_PLATFORM = { platform: "Linux", version: "" };
|
|
|
30
32
|
*/
|
|
31
33
|
const GREASE_BRAND = { brand: "Not=A?Brand", version: "24" };
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
35
|
+
* The most common Chrome screen per device in Speed Kit RUM, in CSS px (physical px / DPR).
|
|
36
|
+
* Source: `rum.pi`, all apps, real page impressions with browser Chrome, snapshot of 2026-10-25.
|
|
37
|
+
* Refresh the values from the same query.
|
|
38
|
+
*
|
|
39
|
+
* - mobile: 1080x2340 @2.8125, the top Android Chrome phone screen (15.8%).
|
|
40
|
+
* - tablet: 1920x1200 @1.5, the top Android Chrome tablet screen (16.6% landscape, 16.4% portrait).
|
|
41
|
+
* - desktop: 1920x1080 @1, the top Chrome desktop screen (21%).
|
|
37
42
|
*/
|
|
38
|
-
const
|
|
39
|
-
desktop: null,
|
|
43
|
+
export const DEVICE_VIEWPORTS = {
|
|
40
44
|
mobile: {
|
|
41
|
-
width:
|
|
42
|
-
height:
|
|
43
|
-
deviceScaleFactor: 2.
|
|
45
|
+
width: 384,
|
|
46
|
+
height: 832,
|
|
47
|
+
deviceScaleFactor: 2.8125,
|
|
44
48
|
isMobile: true,
|
|
45
49
|
hasTouch: true,
|
|
46
50
|
isLandscape: false,
|
|
47
51
|
},
|
|
48
52
|
tablet: {
|
|
49
|
-
width:
|
|
50
|
-
height:
|
|
51
|
-
deviceScaleFactor:
|
|
53
|
+
width: 1280,
|
|
54
|
+
height: 800,
|
|
55
|
+
deviceScaleFactor: 1.5,
|
|
52
56
|
isMobile: true,
|
|
53
57
|
hasTouch: true,
|
|
54
|
-
isLandscape:
|
|
58
|
+
isLandscape: true,
|
|
59
|
+
},
|
|
60
|
+
desktop: {
|
|
61
|
+
width: 1920,
|
|
62
|
+
height: 1080,
|
|
63
|
+
deviceScaleFactor: 1,
|
|
64
|
+
isMobile: false,
|
|
65
|
+
hasTouch: false,
|
|
66
|
+
isLandscape: true,
|
|
55
67
|
},
|
|
56
68
|
};
|
|
57
69
|
/** The device each of the server's default variation user agents stands for. */
|
|
@@ -104,17 +116,20 @@ export function deviceForUserAgent(userAgent) {
|
|
|
104
116
|
*
|
|
105
117
|
* @param browserVersionString - `browser.version()`, e.g. `Chrome/146.0.7680.165`.
|
|
106
118
|
* @param device - The device to present.
|
|
119
|
+
* @param platform - Node platform of the desktop user agent. The fetcher keeps the host's, so its
|
|
120
|
+
* fingerprint matches; `sk onboarding --device desktop` presents Windows.
|
|
107
121
|
*/
|
|
108
|
-
export function deviceEmulation(browserVersionString, device) {
|
|
109
|
-
|
|
122
|
+
export function deviceEmulation(browserVersionString, device, platform = process.platform) {
|
|
123
|
+
// A desktop fetch keeps the window's own viewport, from the launch's `defaultViewport: null`.
|
|
124
|
+
const viewport = device === "desktop" ? null : DEVICE_VIEWPORTS[device];
|
|
110
125
|
const major = chromeMajorVersion(browserVersionString);
|
|
111
126
|
if (!major)
|
|
112
127
|
return { device, viewport };
|
|
113
128
|
if (device === "desktop") {
|
|
114
129
|
return {
|
|
115
130
|
device,
|
|
116
|
-
userAgent: buildHeadedUserAgent(browserVersionString),
|
|
117
|
-
metadata: desktopMetadata(major),
|
|
131
|
+
userAgent: buildHeadedUserAgent(browserVersionString, platform),
|
|
132
|
+
metadata: desktopMetadata(major, platform),
|
|
118
133
|
viewport,
|
|
119
134
|
};
|
|
120
135
|
}
|
|
@@ -56,6 +56,26 @@ describe("deviceEmulation", () => {
|
|
|
56
56
|
expect(emulation.userAgent).to.equal("Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36");
|
|
57
57
|
expect(emulation.viewport?.width).to.be.greaterThan(deviceEmulation(CHROME_VERSION, "mobile").viewport?.width ?? 0);
|
|
58
58
|
});
|
|
59
|
+
it("takes the most common Chrome phone and tablet screens of RUM", () => {
|
|
60
|
+
expect(deviceEmulation(CHROME_VERSION, "mobile").viewport).to.deep.include({
|
|
61
|
+
width: 384,
|
|
62
|
+
height: 832,
|
|
63
|
+
deviceScaleFactor: 2.8125,
|
|
64
|
+
isLandscape: false,
|
|
65
|
+
});
|
|
66
|
+
expect(deviceEmulation(CHROME_VERSION, "tablet").viewport).to.deep.include({
|
|
67
|
+
width: 1280,
|
|
68
|
+
height: 800,
|
|
69
|
+
deviceScaleFactor: 1.5,
|
|
70
|
+
isLandscape: true,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it("presents the desktop on the given platform", () => {
|
|
74
|
+
const emulation = deviceEmulation(CHROME_VERSION, "desktop", "win32");
|
|
75
|
+
expect(emulation.userAgent).to.equal("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36");
|
|
76
|
+
expect(emulation.metadata?.platform).to.equal("Windows");
|
|
77
|
+
expect(emulation.viewport).to.equal(null);
|
|
78
|
+
});
|
|
59
79
|
it("sends client hints that agree with the Android user agent", () => {
|
|
60
80
|
const mobile = deviceEmulation(CHROME_VERSION, "mobile").metadata;
|
|
61
81
|
const tablet = deviceEmulation(CHROME_VERSION, "tablet").metadata;
|
|
@@ -145,7 +145,7 @@ export class DiffServiceFactory {
|
|
|
145
145
|
async loadRuntimeConfig(log, app) {
|
|
146
146
|
if (!app && !this.context.variationsFile) {
|
|
147
147
|
log.writeWarning("no customer: the requests carry Speed Kit's device defaults only, no variations of an app");
|
|
148
|
-
return { variations: {}, authentications: [] };
|
|
148
|
+
return { variations: {}, authentications: [], originMap: {} };
|
|
149
149
|
}
|
|
150
150
|
return new RuntimeConfigSource({
|
|
151
151
|
cli: log,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Browser } from "puppeteer";
|
|
2
|
+
import { BrowserContext } from "../onboarding-model.js";
|
|
3
|
+
/**
|
|
4
|
+
* Emulates the device of `--device` on every page and Service Worker of `browser`: the ones open
|
|
5
|
+
* now, and every one opened later, by the CLI or by an external CDP client.
|
|
6
|
+
*
|
|
7
|
+
* A browser-wide auto-attach holds each new target until its overrides are in, so the first request
|
|
8
|
+
* of a page or worker already carries them. Each override is sent once, when the target appears. A
|
|
9
|
+
* client that overrides the metrics afterwards keeps its own values.
|
|
10
|
+
*
|
|
11
|
+
* The overrides live as long as this session, which lives as long as the browser connection.
|
|
12
|
+
*/
|
|
13
|
+
export declare function emulateDevice(browser: Browser, browserContext: BrowserContext): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { safe } from "../../../helpers/safe.js";
|
|
2
|
+
/**
|
|
3
|
+
* Emulates the device of `--device` on every page and Service Worker of `browser`: the ones open
|
|
4
|
+
* now, and every one opened later, by the CLI or by an external CDP client.
|
|
5
|
+
*
|
|
6
|
+
* A browser-wide auto-attach holds each new target until its overrides are in, so the first request
|
|
7
|
+
* of a page or worker already carries them. Each override is sent once, when the target appears. A
|
|
8
|
+
* client that overrides the metrics afterwards keeps its own values.
|
|
9
|
+
*
|
|
10
|
+
* The overrides live as long as this session, which lives as long as the browser connection.
|
|
11
|
+
*/
|
|
12
|
+
export async function emulateDevice(browser, browserContext) {
|
|
13
|
+
const session = await browser.target().createCDPSession();
|
|
14
|
+
session.on("Target.attachedToTarget", (event) => {
|
|
15
|
+
const target = session.connection()?.session(event.sessionId);
|
|
16
|
+
if (target)
|
|
17
|
+
void emulateTarget(target, event, browserContext);
|
|
18
|
+
});
|
|
19
|
+
await session.send("Target.setAutoAttach", {
|
|
20
|
+
autoAttach: true,
|
|
21
|
+
waitForDebuggerOnStart: true,
|
|
22
|
+
flatten: true,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function emulateTarget(session, { targetInfo, waitingForDebugger }, browserContext) {
|
|
26
|
+
// Not the DevTools window that `devtools: true` docks next to a headed page.
|
|
27
|
+
const isPage = targetInfo.type === "page" && !targetInfo.url.startsWith("devtools:");
|
|
28
|
+
const { userAgent, metadata } = browserContext.emulation;
|
|
29
|
+
// The client hints: the `--user-agent` launch flag changes only the string, so Chrome would still
|
|
30
|
+
// send the host's `Sec-CH-UA-Platform` and `Sec-CH-UA-Mobile`.
|
|
31
|
+
if (userAgent && (isPage || targetInfo.type === "service_worker")) {
|
|
32
|
+
await safe(session.send("Network.setUserAgentOverride", {
|
|
33
|
+
userAgent,
|
|
34
|
+
userAgentMetadata: metadata,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
if (isPage) {
|
|
38
|
+
await safe(session.send("Emulation.setDeviceMetricsOverride", browserContext.getDeviceMetricsOverride()));
|
|
39
|
+
const touch = browserContext.getTouchEmulation();
|
|
40
|
+
await safe(session.send("Emulation.setTouchEmulationEnabled", touch));
|
|
41
|
+
// Without it a mouse click never reaches a touch-only handler in headed mode.
|
|
42
|
+
await safe(session.send("Emulation.setEmitTouchEventsForMouse", {
|
|
43
|
+
enabled: touch.enabled,
|
|
44
|
+
configuration: "mobile",
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
if (waitingForDebugger) {
|
|
48
|
+
await safe(session.send("Runtime.runIfWaitingForDebugger"));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import puppeteerExtra from "puppeteer-extra";
|
|
2
|
+
import { emulateDevice } from "./emulate-device.js";
|
|
2
3
|
/** Launches the onboarding Chrome. Onboarding and browse mode share it, so their hardening cannot drift. */
|
|
3
|
-
export function launchBrowser(browserContext) {
|
|
4
|
-
|
|
4
|
+
export async function launchBrowser(browserContext) {
|
|
5
|
+
const browser = await puppeteerExtra.default.launch(browserContext.getPuppeteerLaunchOptions());
|
|
6
|
+
if (browserContext.emulation) {
|
|
7
|
+
await emulateDevice(browser, browserContext);
|
|
8
|
+
}
|
|
9
|
+
return browser;
|
|
5
10
|
}
|
|
6
11
|
/**
|
|
7
12
|
* Starts from a clean state for `origin`: no service worker, no cookies, no stored data, no
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { CDPSession } from "puppeteer";
|
|
1
|
+
import { CDPSession, Viewport } 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 { DeviceEmulation, FetchDevice } from "../browser-fetch/device-emulation.js";
|
|
8
9
|
export declare const HEADLESS_PARITY_ARGS: string[];
|
|
9
10
|
declare const HEADLESS_DEFAULT_ARGS_TO_DROP: string[];
|
|
10
11
|
export { HEADLESS_DEFAULT_ARGS_TO_DROP };
|
|
12
|
+
/** A device as `--device` emulates it: always with a viewport, also for the desktop. */
|
|
13
|
+
export type BrowserDeviceEmulation = DeviceEmulation & {
|
|
14
|
+
viewport: Viewport;
|
|
15
|
+
};
|
|
11
16
|
export declare const BROWSER_EVENTS: {
|
|
12
17
|
DISCONNECTED: string;
|
|
13
18
|
FETCH_AUTH_REQUIRED: string;
|
|
@@ -44,17 +49,33 @@ export declare class BrowserContext {
|
|
|
44
49
|
readonly debuggingPort: boolean;
|
|
45
50
|
readonly headless: boolean;
|
|
46
51
|
readonly debugPort: number;
|
|
52
|
+
readonly device?: FetchDevice;
|
|
47
53
|
/** Everything sk passes before the customer's chromeFlags. */
|
|
48
54
|
private readonly skArgs;
|
|
49
55
|
readonly browserArgs: string[];
|
|
50
56
|
readonly chromePath: string;
|
|
51
|
-
|
|
57
|
+
/** The device of `--device`, or undefined to leave Chrome as it launches. */
|
|
58
|
+
readonly emulation?: BrowserDeviceEmulation;
|
|
59
|
+
constructor(domain: string, browserVersionString?: string, chromeFlags?: string[], environment?: CliEnvironment, userAgent?: string, debuggingPort?: boolean, headless?: boolean, debugPort?: number, device?: FetchDevice);
|
|
60
|
+
/**
|
|
61
|
+
* The user agent is a launch flag rather than only a CDP override on purpose: a per-page
|
|
62
|
+
* `Network.setUserAgentOverride` never reaches a Service Worker that no CDP client holds, so
|
|
63
|
+
* Speed Kit would resolve the wrong device there, and in headless the dynamic-block refetch
|
|
64
|
+
* would leak the headless token and re-poison the merged body.
|
|
65
|
+
*
|
|
66
|
+
* Pointer, hover and touch are launch flags for the same reason: they apply browser-wide.
|
|
67
|
+
*/
|
|
68
|
+
private getEmulationArgs;
|
|
52
69
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
70
|
+
* Device metrics for `Emulation.setDeviceMetricsOverride`, or null without `--device`.
|
|
71
|
+
*
|
|
72
|
+
* `screenWidth`/`screenHeight` are set explicitly, unlike Puppeteer's own `setViewport`: the Speed
|
|
73
|
+
* Kit snippet persists `window.screen.width` and `devicePixelRatio` into the Service Worker cache,
|
|
74
|
+
* and the Asset API derives image downscaling from exactly those two values.
|
|
56
75
|
*/
|
|
57
|
-
|
|
76
|
+
getDeviceMetricsOverride(): Protocol.Emulation.SetDeviceMetricsOverrideRequest | null;
|
|
77
|
+
/** The touch override that goes with the metrics, or null without `--device`. */
|
|
78
|
+
getTouchEmulation(): Protocol.Emulation.SetTouchEmulationEnabledRequest | null;
|
|
58
79
|
private getBrowserExtensionPath;
|
|
59
80
|
/** The system-specific chromeFlags of the user config, appended to every other arg. */
|
|
60
81
|
private getSystemChromeFlags;
|
|
@@ -3,6 +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 { DEVICE_VIEWPORTS, deviceEmulation, } from "../browser-fetch/device-emulation.js";
|
|
6
7
|
const DEFAULT_BROWSER_ARGS = [
|
|
7
8
|
// No `Translate`: Chrome's translate code has no feature of that name, and Puppeteer disables it anyway.
|
|
8
9
|
"--enable-features=NetworkService",
|
|
@@ -14,13 +15,16 @@ const DEFAULT_BROWSER_ARGS = [
|
|
|
14
15
|
// triggered by the flag above. Value is arbitrary and only used as an identifier.
|
|
15
16
|
"--test-type=speed-kit-cli",
|
|
16
17
|
];
|
|
18
|
+
// Blink enums: HoverType kNone=1, kHover=2; PointerType kCoarse=2, kFine=4.
|
|
19
|
+
const FINE_POINTER_SETTINGS = "--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4";
|
|
20
|
+
const COARSE_POINTER_SETTINGS = "--blink-settings=primaryHoverType=1,availableHoverTypes=1,primaryPointerType=2,availablePointerTypes=2";
|
|
17
21
|
// Headless Chrome differs from headed in ways customer bot detection and responsive layout both
|
|
18
22
|
// key on, so a page can render differently — or not at all — depending on the mode. Each entry
|
|
19
23
|
// below erases one measured difference; see HEADLESS_DEFAULT_ARGS_TO_DROP for the counterpart.
|
|
20
24
|
export const HEADLESS_PARITY_ARGS = [
|
|
21
25
|
// Headless exposes no pointing device, so `hover: none` / `any-pointer: coarse` send sites down
|
|
22
26
|
// their touch code path.
|
|
23
|
-
|
|
27
|
+
FINE_POINTER_SETTINGS,
|
|
24
28
|
// Headless otherwise pins the screen to 800x600, i.e. a tablet breakpoint. --screen-info is what
|
|
25
29
|
// overrides it; Chrome's own --ozone-override-screen-size is not reachable via ignoreDefaultArgs.
|
|
26
30
|
"--window-size=1920,1200",
|
|
@@ -33,6 +37,12 @@ const HEADLESS_DEFAULT_ARGS_TO_DROP = [
|
|
|
33
37
|
"--hide-scrollbars",
|
|
34
38
|
];
|
|
35
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
|
+
/** Room next to an emulated viewport for the DevTools panel that `devtools: true` docks in headed mode. */
|
|
43
|
+
const DEVTOOLS_GUTTER = 520;
|
|
44
|
+
/** What Chrome reports for a touchscreen phone or tablet. */
|
|
45
|
+
const MAX_TOUCH_POINTS = 5;
|
|
36
46
|
export const BROWSER_EVENTS = {
|
|
37
47
|
DISCONNECTED: "disconnected",
|
|
38
48
|
FETCH_AUTH_REQUIRED: "Fetch.authRequired",
|
|
@@ -69,11 +79,14 @@ export class BrowserContext {
|
|
|
69
79
|
debuggingPort;
|
|
70
80
|
headless;
|
|
71
81
|
debugPort;
|
|
82
|
+
device;
|
|
72
83
|
/** Everything sk passes before the customer's chromeFlags. */
|
|
73
84
|
skArgs;
|
|
74
85
|
browserArgs;
|
|
75
86
|
chromePath;
|
|
76
|
-
|
|
87
|
+
/** The device of `--device`, or undefined to leave Chrome as it launches. */
|
|
88
|
+
emulation;
|
|
89
|
+
constructor(domain, browserVersionString = "unknown", chromeFlags, environment, userAgent, debuggingPort = false, headless = false, debugPort = 9222, device) {
|
|
77
90
|
this.domain = domain;
|
|
78
91
|
this.browserVersionString = browserVersionString;
|
|
79
92
|
this.chromeFlags = chromeFlags;
|
|
@@ -82,6 +95,7 @@ export class BrowserContext {
|
|
|
82
95
|
this.debuggingPort = debuggingPort;
|
|
83
96
|
this.headless = headless;
|
|
84
97
|
this.debugPort = debugPort;
|
|
98
|
+
this.device = device;
|
|
85
99
|
this.domain = domain;
|
|
86
100
|
this.chromeFlags = chromeFlags || [];
|
|
87
101
|
this.chromePath = resolve(environment.settings.chromePath);
|
|
@@ -95,14 +109,19 @@ export class BrowserContext {
|
|
|
95
109
|
const temporaryProfileDirectory = browserConfig.loadProfileTempDir();
|
|
96
110
|
browserArguments.push(`--user-data-dir=${temporaryProfileDirectory}`);
|
|
97
111
|
}
|
|
98
|
-
if (
|
|
99
|
-
this.
|
|
100
|
-
|
|
112
|
+
if (device) {
|
|
113
|
+
this.emulation = {
|
|
114
|
+
...deviceEmulation(browserVersionString, device, DESKTOP_PLATFORM),
|
|
115
|
+
viewport: DEVICE_VIEWPORTS[device],
|
|
116
|
+
};
|
|
101
117
|
}
|
|
118
|
+
this.userAgent ??=
|
|
119
|
+
this.emulation?.userAgent ??
|
|
120
|
+
(this.headless ? buildHeadedUserAgent(browserVersionString) : undefined);
|
|
102
121
|
this.skArgs = [
|
|
103
122
|
...browserArguments,
|
|
104
123
|
`--unsafely-treat-insecure-origin-as-secure=${domain}`,
|
|
105
|
-
...this.
|
|
124
|
+
...this.getEmulationArgs(),
|
|
106
125
|
];
|
|
107
126
|
this.browserArgs = [
|
|
108
127
|
...this.skArgs,
|
|
@@ -111,18 +130,68 @@ export class BrowserContext {
|
|
|
111
130
|
];
|
|
112
131
|
}
|
|
113
132
|
/**
|
|
114
|
-
*
|
|
115
|
-
* `Network.setUserAgentOverride` never reaches
|
|
116
|
-
*
|
|
133
|
+
* The user agent is a launch flag rather than only a CDP override on purpose: a per-page
|
|
134
|
+
* `Network.setUserAgentOverride` never reaches a Service Worker that no CDP client holds, so
|
|
135
|
+
* Speed Kit would resolve the wrong device there, and in headless the dynamic-block refetch
|
|
136
|
+
* would leak the headless token and re-poison the merged body.
|
|
137
|
+
*
|
|
138
|
+
* Pointer, hover and touch are launch flags for the same reason: they apply browser-wide.
|
|
117
139
|
*/
|
|
118
|
-
|
|
140
|
+
getEmulationArgs() {
|
|
141
|
+
const userAgentArgs = this.userAgent
|
|
142
|
+
? [`--user-agent=${this.userAgent}`]
|
|
143
|
+
: [];
|
|
144
|
+
if (this.emulation) {
|
|
145
|
+
const { width, height, hasTouch } = this.emulation.viewport;
|
|
146
|
+
const windowWidth = this.headless ? width : width + DEVTOOLS_GUTTER;
|
|
147
|
+
return [
|
|
148
|
+
hasTouch ? COARSE_POINTER_SETTINGS : FINE_POINTER_SETTINGS,
|
|
149
|
+
// Makes `'ontouchend' in document` match the device. The Speed Kit snippet persists it into
|
|
150
|
+
// the Service Worker as `supportsTouch`, and every RuleSet of the config is built with it.
|
|
151
|
+
`--touch-events=${hasTouch ? "enabled" : "disabled"}`,
|
|
152
|
+
`--window-size=${windowWidth},${height}`,
|
|
153
|
+
// Headless otherwise pins the screen to 800x600; --screen-info is what overrides it.
|
|
154
|
+
...(this.headless ? [`--screen-info={${windowWidth}x${height}}`] : []),
|
|
155
|
+
...userAgentArgs,
|
|
156
|
+
];
|
|
157
|
+
}
|
|
119
158
|
if (!this.headless) {
|
|
120
159
|
return [];
|
|
121
160
|
}
|
|
122
|
-
return [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
161
|
+
return [...HEADLESS_PARITY_ARGS, ...userAgentArgs];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Device metrics for `Emulation.setDeviceMetricsOverride`, or null without `--device`.
|
|
165
|
+
*
|
|
166
|
+
* `screenWidth`/`screenHeight` are set explicitly, unlike Puppeteer's own `setViewport`: the Speed
|
|
167
|
+
* Kit snippet persists `window.screen.width` and `devicePixelRatio` into the Service Worker cache,
|
|
168
|
+
* and the Asset API derives image downscaling from exactly those two values.
|
|
169
|
+
*/
|
|
170
|
+
getDeviceMetricsOverride() {
|
|
171
|
+
if (!this.emulation) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const { width, height, deviceScaleFactor, isMobile, isLandscape } = this.emulation.viewport;
|
|
175
|
+
return {
|
|
176
|
+
width,
|
|
177
|
+
height,
|
|
178
|
+
screenWidth: width,
|
|
179
|
+
screenHeight: height,
|
|
180
|
+
deviceScaleFactor,
|
|
181
|
+
mobile: isMobile,
|
|
182
|
+
screenOrientation: isLandscape
|
|
183
|
+
? { type: "landscapePrimary", angle: 90 }
|
|
184
|
+
: { type: "portraitPrimary", angle: 0 },
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** The touch override that goes with the metrics, or null without `--device`. */
|
|
188
|
+
getTouchEmulation() {
|
|
189
|
+
if (!this.emulation) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return this.emulation.viewport.hasTouch
|
|
193
|
+
? { enabled: true, maxTouchPoints: MAX_TOUCH_POINTS }
|
|
194
|
+
: { enabled: false };
|
|
126
195
|
}
|
|
127
196
|
getBrowserExtensionPath() {
|
|
128
197
|
if (this.environment?.settings.chromeExtensionPaths) {
|
|
@@ -188,7 +257,11 @@ export class BrowserContext {
|
|
|
188
257
|
// the "Chrome is being controlled by automated test software" infobar.
|
|
189
258
|
ignoreDefaultArgs: [
|
|
190
259
|
"--enable-automation",
|
|
191
|
-
|
|
260
|
+
// Keep Puppeteer's --hide-scrollbars for a touch device: it has overlay scrollbars, so
|
|
261
|
+
// restoring the 15px desktop ones would be the wrong parity to fix.
|
|
262
|
+
...(this.headless && !this.emulation?.viewport.hasTouch
|
|
263
|
+
? HEADLESS_DEFAULT_ARGS_TO_DROP
|
|
264
|
+
: []),
|
|
192
265
|
],
|
|
193
266
|
};
|
|
194
267
|
// One way for every Chromium build. Branded Chrome ignores
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Interfaces } from "@oclif/core";
|
|
2
2
|
import { CliEnvironment, CommandContextValues } from "../cli/index.js";
|
|
3
|
+
import { FetchDevice } from "../browser-fetch/device-emulation.js";
|
|
3
4
|
/**
|
|
4
5
|
* Gives a bare `--inject` its default value, because oclif knows no flag with an optional value.
|
|
5
6
|
* A value is the next argument, unless that argument is a flag.
|
|
@@ -18,6 +19,8 @@ declare const flags: {
|
|
|
18
19
|
verboseLevel: Interfaces.BooleanFlag<boolean>;
|
|
19
20
|
ignoreContentSecurityPolicy: Interfaces.BooleanFlag<boolean>;
|
|
20
21
|
headless: Interfaces.BooleanFlag<boolean>;
|
|
22
|
+
device: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
23
|
+
mobile: Interfaces.BooleanFlag<boolean>;
|
|
21
24
|
browse: Interfaces.BooleanFlag<boolean>;
|
|
22
25
|
inject: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
23
26
|
app: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
@@ -38,6 +41,8 @@ export interface OnboardingServiceBuildContextValues extends CommandContextValue
|
|
|
38
41
|
readonly debuggingPort: boolean;
|
|
39
42
|
readonly headless: boolean;
|
|
40
43
|
readonly debugPort: number;
|
|
44
|
+
/** The device `--device` or `--mobile` emulates. */
|
|
45
|
+
readonly device?: FetchDevice;
|
|
41
46
|
readonly browserFetch: boolean;
|
|
42
47
|
readonly browse: boolean;
|
|
43
48
|
readonly inject: boolean;
|
|
@@ -62,6 +67,8 @@ export declare class OnboardingServiceBuildContext extends OnboardingServiceBuil
|
|
|
62
67
|
verboseLevel: Interfaces.BooleanFlag<boolean>;
|
|
63
68
|
ignoreContentSecurityPolicy: Interfaces.BooleanFlag<boolean>;
|
|
64
69
|
headless: Interfaces.BooleanFlag<boolean>;
|
|
70
|
+
device: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
71
|
+
mobile: Interfaces.BooleanFlag<boolean>;
|
|
65
72
|
browse: Interfaces.BooleanFlag<boolean>;
|
|
66
73
|
inject: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
67
74
|
app: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Args, Flags } from "@oclif/core";
|
|
2
2
|
import { CLI_CONFIG_IS_TEST, CLI_CONFIG_NAME, } from "../integration-api/customer-config-flags.js";
|
|
3
3
|
import { Context } from "../../models/context.js";
|
|
4
|
+
import { FETCH_DEVICES, } from "../browser-fetch/device-emulation.js";
|
|
4
5
|
/** The value `--inject` gets when it is passed without one. */
|
|
5
6
|
const LATEST_INSTALLATION = "latest";
|
|
6
7
|
/**
|
|
@@ -64,6 +65,15 @@ const flags = {
|
|
|
64
65
|
default: false,
|
|
65
66
|
description: "Run Chrome in headless mode (for CI environments). Implicitly enables remote debugging port.",
|
|
66
67
|
}),
|
|
68
|
+
device: Flags.string({
|
|
69
|
+
options: [...FETCH_DEVICES],
|
|
70
|
+
description: "Emulate a device in every page and Service Worker: user agent, client hints, viewport, pointer and touch. Without it, Chrome runs as it launches.",
|
|
71
|
+
}),
|
|
72
|
+
mobile: Flags.boolean({
|
|
73
|
+
char: "m",
|
|
74
|
+
exclusive: ["device"],
|
|
75
|
+
description: "Same as --device mobile",
|
|
76
|
+
}),
|
|
67
77
|
browse: Flags.boolean({
|
|
68
78
|
default: false,
|
|
69
79
|
description: "Open the live site in the onboarding Chrome, with its extensions, but without request interception or Speed Kit injection. Takes the domain from -d or from the customer config.",
|
|
@@ -99,6 +109,8 @@ export class OnboardingServiceBuildContext extends Context() {
|
|
|
99
109
|
debuggingPort: parsedFlags.debuggingPort,
|
|
100
110
|
headless: parsedFlags.headless,
|
|
101
111
|
debugPort: parsedFlags.debugPort,
|
|
112
|
+
device: parsedFlags.device ??
|
|
113
|
+
(parsedFlags.mobile ? "mobile" : undefined),
|
|
102
114
|
browserFetch: parsedFlags.browserFetch,
|
|
103
115
|
browse: parsedFlags.browse,
|
|
104
116
|
app: parsedFlags.app,
|