@speedkit/cli 4.20.2 → 4.20.3

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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [4.20.3](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.20.2...v4.20.3) (2026-08-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **onboarding:** make headless launch match headed ([aa9af3e](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/aa9af3ea69602c82ef30ffa547b33a32092258e5))
7
+
1
8
  ## [4.20.2](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.20.1...v4.20.2) (2026-08-07)
2
9
 
3
10
 
package/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @speedkit/cli
21
21
  $ sk COMMAND
22
22
  running command...
23
23
  $ sk (--version)
24
- @speedkit/cli/4.20.2 linux-x64 node-v22.23.2
24
+ @speedkit/cli/4.20.3 linux-x64 node-v22.23.2
25
25
  $ sk --help [COMMAND]
26
26
  USAGE
27
27
  $ sk COMMAND
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The user agent headed Chrome sends for this build. Headless would otherwise say
3
+ * `HeadlessChrome/<version>`, which some origins treat as a crawler.
4
+ *
5
+ * @param browserVersionString `chrome --version` output, e.g. `Google Chrome for Testing 146.0.7680.165`
6
+ */
7
+ export declare function buildHeadedUserAgent(browserVersionString: string, platform?: string): string | undefined;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Chrome's reduced User-Agent, as documented at https://www.chromium.org/updates/ua-reduction/:
3
+ *
4
+ * Mozilla/5.0 (<unifiedPlatform>) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/<major>.0.0.0 Safari/537.36
5
+ *
6
+ * Only the major version moves — everything after it is frozen at 0.0.0, and the platform tokens are
7
+ * literal values that "will not update even if a user is on an updated operating system or device".
8
+ * So taking the major version from the installed binary keeps this current on its own.
9
+ */
10
+ const UNIFIED_PLATFORMS = {
11
+ darwin: "Macintosh; Intel Mac OS X 10_15_7",
12
+ win32: "Windows NT 10.0; Win64; x64",
13
+ };
14
+ // Chrome reports X11 for every other *nix build it ships.
15
+ const DEFAULT_UNIFIED_PLATFORM = "X11; Linux x86_64";
16
+ /**
17
+ * The user agent headed Chrome sends for this build. Headless would otherwise say
18
+ * `HeadlessChrome/<version>`, which some origins treat as a crawler.
19
+ *
20
+ * @param browserVersionString `chrome --version` output, e.g. `Google Chrome for Testing 146.0.7680.165`
21
+ */
22
+ export function buildHeadedUserAgent(browserVersionString, platform = process.platform) {
23
+ const majorVersion = browserVersionString.match(/(\d+)\.\d+\.\d+\.\d+/)?.[1];
24
+ if (!majorVersion) {
25
+ return undefined;
26
+ }
27
+ const unifiedPlatform = UNIFIED_PLATFORMS[platform] ?? DEFAULT_UNIFIED_PLATFORM;
28
+ return `Mozilla/5.0 (${unifiedPlatform}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${majorVersion}.0.0.0 Safari/537.36`;
29
+ }
@@ -0,0 +1,30 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { buildHeadedUserAgent } from "./headed-user-agent.js";
4
+ const CHROME_VERSION = "Google Chrome for Testing 146.0.7680.165";
5
+ describe("buildHeadedUserAgent", () => {
6
+ it("builds the reduced user agent for Linux", () => {
7
+ expect(buildHeadedUserAgent(CHROME_VERSION, "linux")).to.equal("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36");
8
+ });
9
+ it("builds the reduced user agent for macOS", () => {
10
+ expect(buildHeadedUserAgent(CHROME_VERSION, "darwin")).to.equal("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36");
11
+ });
12
+ it("builds the reduced user agent for Windows", () => {
13
+ expect(buildHeadedUserAgent(CHROME_VERSION, "win32")).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");
14
+ });
15
+ it("falls back to the X11 platform token on other unix builds", () => {
16
+ expect(buildHeadedUserAgent(CHROME_VERSION, "freebsd")).to.include("(X11; Linux x86_64)");
17
+ });
18
+ it("freezes everything after the major version", () => {
19
+ expect(buildHeadedUserAgent("Google Chrome 131.0.6778.86", "linux")).to.include("Chrome/131.0.0.0 ");
20
+ });
21
+ it("reads the version from the Windows ProductName + FileVersion shape", () => {
22
+ expect(buildHeadedUserAgent("Google Chrome 146.0.7680.165", "win32")).to.include("Chrome/146.0.0.0 ");
23
+ });
24
+ it("never advertises the headless token", () => {
25
+ expect(buildHeadedUserAgent(CHROME_VERSION, "linux")).to.not.include("HeadlessChrome");
26
+ });
27
+ it("returns undefined when the version string has no version in it", () => {
28
+ expect(buildHeadedUserAgent("unknown", "linux")).to.equal(undefined);
29
+ });
30
+ });
@@ -5,6 +5,8 @@ import { AbortResponse } from "./browser/abort-response.js";
5
5
  import { task } from "./todo-collector.js";
6
6
  import { VanillaPuppeteer } from "puppeteer-extra";
7
7
  import { Command } from "@oclif/core/command";
8
+ declare const HEADLESS_DEFAULT_ARGS_TO_DROP: string[];
9
+ export { HEADLESS_DEFAULT_ARGS_TO_DROP };
8
10
  export declare const BROWSER_EVENTS: {
9
11
  DISCONNECTED: string;
10
12
  FETCH_AUTH_REQUIRED: string;
@@ -43,6 +45,12 @@ export declare class BrowserContext {
43
45
  readonly browserArgs: string[];
44
46
  readonly chromePath: string;
45
47
  constructor(domain: string, browserVersionString?: string, chromeFlags?: string[], userConfig?: UserCliConfig, userAgent?: string, debuggingPort?: boolean, headless?: boolean, debugPort?: number);
48
+ /**
49
+ * Applied as a launch flag rather than over CDP on purpose: a per-page
50
+ * `Network.setUserAgentOverride` never reaches the Service Worker, so Speed Kit's dynamic-block
51
+ * refetch would still leak the headless token and re-poison the merged body.
52
+ */
53
+ private getHeadlessParityArgs;
46
54
  private isChromeBrowser;
47
55
  private getBrowserExtensionPath;
48
56
  getPuppeteerLaunchOptions(): Parameters<VanillaPuppeteer["launch"]>[0];
@@ -1,6 +1,7 @@
1
1
  import { Flags } from "@oclif/core";
2
2
  import { CLI_CONFIG_IS_TEST, CLI_CONFIG_NAME, CLIParameters, CLIParametersChar, } from "../../models/cli-parameters.js";
3
3
  import { BrowserConfig } from "./browser/config/browser-config.js";
4
+ import { buildHeadedUserAgent } from "./browser/executable/headed-user-agent.js";
4
5
  import { resolve } from "node:path";
5
6
  const DEFAULT_BROWSER_ARGS = [
6
7
  "--enable-features=Translate,NetworkService",
@@ -12,6 +13,25 @@ const DEFAULT_BROWSER_ARGS = [
12
13
  // triggered by the flag above. Value is arbitrary and only used as an identifier.
13
14
  "--test-type=speed-kit-cli",
14
15
  ];
16
+ // Headless Chrome differs from headed in ways customer bot detection and responsive layout both
17
+ // key on, so a page can render differently — or not at all — depending on the mode. Each entry
18
+ // below erases one measured difference; see HEADLESS_DEFAULT_ARGS_TO_DROP for the counterpart.
19
+ const HEADLESS_PARITY_ARGS = [
20
+ // Headless exposes no pointing device, so `hover: none` / `any-pointer: coarse` send sites down
21
+ // their touch code path.
22
+ "--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4",
23
+ // Headless otherwise pins the screen to 800x600, i.e. a tablet breakpoint. --screen-info is what
24
+ // overrides it; Chrome's own --ozone-override-screen-size is not reachable via ignoreDefaultArgs.
25
+ "--window-size=1920,1200",
26
+ "--screen-info={1920x1200}",
27
+ ];
28
+ // Puppeteer-injected headless defaults with no headed equivalent. ignoreDefaultArgs only filters what
29
+ // Puppeteer itself adds, so a spec asserts every entry is still in its defaultArgs.
30
+ const HEADLESS_DEFAULT_ARGS_TO_DROP = [
31
+ // Scrollbar width 0 instead of 15 narrows the layout viewport and skews layout-shift work.
32
+ "--hide-scrollbars",
33
+ ];
34
+ export { HEADLESS_DEFAULT_ARGS_TO_DROP };
15
35
  export const BROWSER_EVENTS = {
16
36
  DISCONNECTED: "disconnected",
17
37
  FETCH_AUTH_REQUIRED: "Fetch.authRequired",
@@ -61,7 +81,8 @@ export class BrowserContext {
61
81
  this.domain = domain;
62
82
  this.chromeFlags = chromeFlags || [];
63
83
  this.chromePath = resolve(userConfig.chromePath);
64
- const browserArguments = DEFAULT_BROWSER_ARGS;
84
+ // Copy: pushing onto the shared module-level array leaked args into every later instance.
85
+ const browserArguments = [...DEFAULT_BROWSER_ARGS];
65
86
  if (userConfig?.chromeUserProfilePath) {
66
87
  browserArguments.push(`--user-data-dir=${userConfig?.chromeUserProfilePath}`);
67
88
  }
@@ -70,12 +91,32 @@ export class BrowserContext {
70
91
  const temporaryProfileDirectory = browserConfig.loadProfileTempDir();
71
92
  browserArguments.push(`--user-data-dir=${temporaryProfileDirectory}`);
72
93
  }
94
+ if (this.headless) {
95
+ this.userAgent =
96
+ this.userAgent ?? buildHeadedUserAgent(browserVersionString);
97
+ }
73
98
  this.browserArgs = [
74
99
  ...browserArguments,
75
100
  `--unsafely-treat-insecure-origin-as-secure=${domain}`,
101
+ ...this.getHeadlessParityArgs(),
102
+ // Last, so a customer's chromeFlags override our defaults — Chrome takes the last occurrence.
76
103
  ...this.chromeFlags,
77
104
  ];
78
105
  }
106
+ /**
107
+ * Applied as a launch flag rather than over CDP on purpose: a per-page
108
+ * `Network.setUserAgentOverride` never reaches the Service Worker, so Speed Kit's dynamic-block
109
+ * refetch would still leak the headless token and re-poison the merged body.
110
+ */
111
+ getHeadlessParityArgs() {
112
+ if (!this.headless) {
113
+ return [];
114
+ }
115
+ return [
116
+ ...HEADLESS_PARITY_ARGS,
117
+ ...(this.userAgent ? [`--user-agent=${this.userAgent}`] : []),
118
+ ];
119
+ }
79
120
  isChromeBrowser() {
80
121
  return !!/chrome/i.test(this.browserVersionString);
81
122
  }
@@ -95,7 +136,10 @@ export class BrowserContext {
95
136
  args: this.browserArgs,
96
137
  // Strip Puppeteer's default `--enable-automation` so Chrome doesn't show
97
138
  // the "Chrome is being controlled by automated test software" infobar.
98
- ignoreDefaultArgs: ["--enable-automation"],
139
+ ignoreDefaultArgs: [
140
+ "--enable-automation",
141
+ ...(this.headless ? HEADLESS_DEFAULT_ARGS_TO_DROP : []),
142
+ ],
99
143
  };
100
144
  if (this.userConfig?.chromeExtensionPaths) {
101
145
  if (this.isChromeBrowser()) {
@@ -1,12 +1,20 @@
1
1
  import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
- import { BrowserContext } from "./onboarding-model.js";
3
+ import { BrowserContext, HEADLESS_DEFAULT_ARGS_TO_DROP, } from "./onboarding-model.js";
4
+ import { buildHeadedUserAgent } from "./browser/executable/headed-user-agent.js";
4
5
  // Providing chromeUserProfilePath keeps BrowserContext off the filesystem
5
6
  // (it skips the temp-profile branch in the constructor).
6
7
  const userConfig = {
7
8
  chromePath: "/usr/bin/google-chrome",
8
9
  chromeUserProfilePath: "/tmp/sk-test-profile",
9
10
  };
11
+ function newContext(headless, { chromeFlags = [], userAgent, browserVersionString = "Google Chrome for Testing 146.0.7680.165", } = {}) {
12
+ return new BrowserContext("example.com", browserVersionString, chromeFlags, userConfig, userAgent, false, headless, undefined);
13
+ }
14
+ function launchArgs(headless, overrides = {}) {
15
+ return newContext(headless, overrides).getPuppeteerLaunchOptions()
16
+ .args;
17
+ }
10
18
  function remoteDebuggingArg(debuggingPort, headless, debugPort) {
11
19
  const context = new BrowserContext("example.com", "Chrome/120", [], userConfig, undefined, debuggingPort, headless, debugPort);
12
20
  const args = context.getPuppeteerLaunchOptions().args;
@@ -26,3 +34,65 @@ describe("BrowserContext.getPuppeteerLaunchOptions remote debugging port", () =>
26
34
  expect(remoteDebuggingArg(false, false, 9223)).to.equal(undefined);
27
35
  });
28
36
  });
37
+ describe("BrowserContext headless/headed parity", () => {
38
+ const userAgentOf = (args) => args.find((arg) => arg.startsWith("--user-agent="));
39
+ it("derives the headed user agent from the installed Chrome version", () => {
40
+ expect(userAgentOf(launchArgs(true))).to.equal(`--user-agent=${buildHeadedUserAgent("Google Chrome for Testing 146.0.7680.165")}`);
41
+ });
42
+ it("never contains the HeadlessChrome token", () => {
43
+ expect(launchArgs(true).join(" ")).to.not.include("HeadlessChrome");
44
+ });
45
+ it("leaves the user agent to Chrome in headed mode", () => {
46
+ expect(userAgentOf(launchArgs(false))).to.equal(undefined);
47
+ });
48
+ it("prefers an explicitly provided user agent", () => {
49
+ expect(userAgentOf(launchArgs(true, { userAgent: "custom-agent" }))).to.equal("--user-agent=custom-agent");
50
+ });
51
+ it("omits the flag when the Chrome version cannot be read", () => {
52
+ expect(userAgentOf(launchArgs(true, { browserVersionString: "unknown" }))).to.equal(undefined);
53
+ });
54
+ it("restores hover and fine-pointer support", () => {
55
+ expect(launchArgs(true)).to.include("--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4");
56
+ });
57
+ it("overrides the 800x600 headless screen", () => {
58
+ expect(launchArgs(true)).to.include.members([
59
+ "--window-size=1920,1200",
60
+ "--screen-info={1920x1200}",
61
+ ]);
62
+ });
63
+ it("applies no parity args in headed mode", () => {
64
+ const headedArgs = launchArgs(false);
65
+ expect(headedArgs).to.not.include("--window-size=1920,1200");
66
+ expect(headedArgs.some((arg) => arg.startsWith("--blink-settings="))).to.equal(false);
67
+ });
68
+ it("lets customer chromeFlags win over the parity defaults", () => {
69
+ const args = launchArgs(true, {
70
+ chromeFlags: ["--window-size=390,844", "--user-agent=mobile-agent"],
71
+ });
72
+ // Chrome takes the last occurrence of a switch, so the customer values must come last.
73
+ expect(args.lastIndexOf("--window-size=390,844")).to.be.greaterThan(args.lastIndexOf("--window-size=1920,1200"));
74
+ expect(args.lastIndexOf("--user-agent=mobile-agent")).to.be.greaterThan(args.findIndex((arg) => arg.startsWith("--user-agent=Mozilla/5.0")));
75
+ });
76
+ it("drops the Puppeteer headless defaults that have no headed equivalent", () => {
77
+ expect(newContext(true).getPuppeteerLaunchOptions().ignoreDefaultArgs).to.include.members(["--enable-automation", "--hide-scrollbars"]);
78
+ });
79
+ // ignoreDefaultArgs filters Puppeteer's own args by exact string. Anything Chrome adds itself is
80
+ // unreachable that way, and a Puppeteer bump that renames or drops an arg would silently turn an
81
+ // entry into a no-op — which is how --ozone-override-screen-size got in here in the first place.
82
+ it("only ignores args Puppeteer actually adds", async () => {
83
+ const { defaultArgs } = await import("puppeteer");
84
+ const puppeteerHeadlessArgs = defaultArgs({ headless: true });
85
+ expect(puppeteerHeadlessArgs).to.include.members([
86
+ ...HEADLESS_DEFAULT_ARGS_TO_DROP,
87
+ "--enable-automation",
88
+ ]);
89
+ });
90
+ it("keeps only --enable-automation ignored in headed mode", () => {
91
+ expect(newContext(false).getPuppeteerLaunchOptions().ignoreDefaultArgs).to.deep.equal(["--enable-automation"]);
92
+ });
93
+ it("does not leak args between instances", () => {
94
+ const first = launchArgs(true).length;
95
+ launchArgs(true);
96
+ expect(launchArgs(true).length).to.equal(first);
97
+ });
98
+ });
@@ -1001,5 +1001,5 @@
1001
1001
  ]
1002
1002
  }
1003
1003
  },
1004
- "version": "4.20.2"
1004
+ "version": "4.20.3"
1005
1005
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.20.2",
4
+ "version": "4.20.3",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"