@gnawbit/tabretake 0.4.0 → 0.4.2

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/scripts/cli.mjs CHANGED
@@ -9,13 +9,13 @@ Usage:
9
9
  tabretake capabilities [--json]
10
10
  tabretake doctor [--json]
11
11
  tabretake validate --config demo.json [--json]
12
- tabretake init --url <url> [--out demo.json]
12
+ tabretake init --url <url> [--out demo.json] [--auto] [--preset midnight|daylight|paper|slate]
13
13
  tabretake plan --url <url> [--out plan.json] [--login] [--storage-state auth.json]
14
14
  tabretake record --config demo.json [--out demo] [--login] [--storage-state auth.json]
15
15
  tabretake preview --config demo.json [--headless] [--json]
16
- tabretake render --config demo.json [--out demo] [--video recording.mp4] [--vertical] [--no-gif]
16
+ tabretake render --config demo.json [--out demo] [--video recording.mp4] [--vertical] [--no-gif] [--preset <name>]
17
17
  tabretake serve [--port 4173] [--dir examples/site]
18
- tabretake demo [--story readme|onboarding|release] [--out demo]
18
+ tabretake demo [--story readme|onboarding|release] [--out demo] [--preset <name>]
19
19
 
20
20
  Examples:
21
21
  tabretake init --url https://your-app.com
@@ -33,8 +33,11 @@ Options:
33
33
  --viewport Viewport, e.g. 1440x810 (default from config)
34
34
  --headed Watch the recording happen (default false)
35
35
  --vertical Also render a 9:16 vertical video + GIF.
36
+ --vertical-zoom Override portrait focus zoom (1–10; otherwise uses --zoom).
36
37
  --video Use an existing screen recording; the config needs "marks".
37
38
  --no-gif Skip GIF export.
39
+ --browser Browser channel: auto (default), chromium, chrome or msedge.
40
+ --preset Brand theme preset: midnight, daylight, paper or slate.
38
41
  --poster-at Choose the poster time in output seconds, e.g. 4.5.
39
42
  --zoom-duration Ease between click targets in seconds (default 0.35; 0 for cuts).
40
43
  `;
package/scripts/demo.mjs CHANGED
@@ -31,8 +31,14 @@ export async function demo(argv) {
31
31
  server.url,
32
32
  "--out",
33
33
  values.out,
34
+ ...(values.browser ? ["--browser", values.browser] : []),
35
+ ]);
36
+ await render([
37
+ "--config",
38
+ path.join(values.out, "record.json"),
39
+ "--vertical",
40
+ ...(values.preset ? ["--preset", values.preset] : []),
34
41
  ]);
35
- await render(["--config", path.join(values.out, "record.json"), "--vertical"]);
36
42
  } finally {
37
43
  await server.close();
38
44
  }
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { execFile } from "node:child_process";
3
3
  import { promisify } from "node:util";
4
+ import { findSystemBrowser } from "./lib/system-browser.mjs";
4
5
  import { findCjkFont, findFont } from "./lib/fonts.mjs";
5
6
  import { parseCommand } from "./lib/options.mjs";
6
7
  import { nodeRange, schemaVersion, supportsNodeVersion, version } from "./lib/metadata.mjs";
@@ -15,6 +16,7 @@ export async function diagnose({
15
16
  exists = existsSync,
16
17
  run = (file) => exec(file, ["-version"], { windowsHide: true, timeout: 10000 }),
17
18
  fonts = { latin: findFont, cjk: findCjkFont },
19
+ systemBrowser = () => findSystemBrowser({ exists }),
18
20
  } = {}) {
19
21
  const checks = [];
20
22
  async function check(id, required, hint, probe) {
@@ -37,11 +39,17 @@ export async function diagnose({
37
39
  return (stdout || stderr).split("\n")[0].trim();
38
40
  });
39
41
  }
40
- await check("chromium", true, "Run tabretake setup (from source: node bin/tabretake.mjs setup).", async () => {
42
+ await check("chromium", true, "Run tabretake setup (or install Chrome/Edge for automatic fallback).", async () => {
41
43
  const { chromium } = await load("playwright");
42
44
  const file = chromium.executablePath();
43
- if (!exists(file)) throw new Error("Chromium executable not found");
44
- return "Executable found; browser launch and system libraries are not tested.";
45
+ if (exists(file)) {
46
+ return "Executable found; browser launch and system libraries are not tested.";
47
+ }
48
+ const fallback = systemBrowser();
49
+ if (fallback) {
50
+ return `Using system ${fallback.channel} fallback; run tabretake setup for pinned Chromium.`;
51
+ }
52
+ throw new Error("Chromium executable not found and no Chrome/Edge fallback detected");
45
53
  });
46
54
  await check("sharp", true, reinstall, async () => {
47
55
  const { default: sharp } = await load("sharp");
package/scripts/init.mjs CHANGED
@@ -2,6 +2,65 @@ import { mkdir, writeFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { parseCommand } from "./lib/options.mjs";
4
4
  import { createReporter } from "./lib/report.mjs";
5
+ import { resolveTheme } from "./lib/themes.mjs";
6
+ import { extractPlan } from "./plan.mjs";
7
+
8
+ export function buildAutoSteps(elements) {
9
+ const steps = [{ action: "wait", ms: 600 }];
10
+ const interactive = (elements || []).filter((el) => {
11
+ if (el.type === "password" || el.type === "hidden") return false;
12
+ return Boolean(el.selector && (el.text || el.label || el.placeholder || el.name));
13
+ });
14
+
15
+ const inputs = interactive.filter((el) => el.tag === "input" || el.tag === "textarea" || el.role === "textbox");
16
+ const buttons = interactive.filter((el) => el.tag === "button" || el.tag === "a" || el.role === "button" || el.role === "link");
17
+
18
+ const chosen = [];
19
+ if (inputs.length > 0) {
20
+ chosen.push(inputs[0]);
21
+ }
22
+ for (const btn of buttons) {
23
+ if (chosen.length >= 3) break;
24
+ if (!chosen.some((c) => c.selector === btn.selector)) {
25
+ chosen.push(btn);
26
+ }
27
+ }
28
+ for (const el of interactive) {
29
+ if (chosen.length >= 3) break;
30
+ if (!chosen.some((c) => c.selector === el.selector)) {
31
+ chosen.push(el);
32
+ }
33
+ }
34
+
35
+ for (const el of chosen) {
36
+ if (el.tag === "input" || el.tag === "textarea" || el.role === "textbox") {
37
+ const caption = el.label || el.placeholder || (el.name ? `Enter ${el.name}` : "Input demo text");
38
+ steps.push({
39
+ action: "type",
40
+ selector: el.selector,
41
+ value: "Test drive",
42
+ pause: 400,
43
+ caption: `Input: ${caption}`,
44
+ });
45
+ } else {
46
+ const caption = el.text || el.label || (el.role ? `${el.role}` : "Click target");
47
+ steps.push({
48
+ action: "click",
49
+ selector: el.selector,
50
+ pause: 600,
51
+ caption: `Click: ${caption}`,
52
+ });
53
+ }
54
+ steps.push({ action: "wait", ms: 600 });
55
+ }
56
+
57
+ if (steps.length === 1) {
58
+ steps.push({ action: "wait", ms: 1500 });
59
+ } else {
60
+ steps.push({ action: "wait", ms: 1200 });
61
+ }
62
+ return steps;
63
+ }
5
64
 
6
65
  export async function init(argv) {
7
66
  const { values } = parseCommand("init", argv);
@@ -18,14 +77,27 @@ export async function init(argv) {
18
77
  throw new Error("Use a complete http:// or https:// URL");
19
78
  }
20
79
 
80
+ let steps = [{ action: "wait", ms: 1500 }];
81
+ if (values.auto) {
82
+ reporter.log("Scanning page to generate interactive steps (--auto)...");
83
+ try {
84
+ const { elements } = await extractPlan(url.href, { browser: values.browser });
85
+ steps = buildAutoSteps(elements);
86
+ reporter.log(`Generated ${steps.length} step(s) from discovered interactive controls.`);
87
+ } catch (err) {
88
+ reporter.warn(`Could not scan page for --auto (${err.message}); falling back to starter.`);
89
+ }
90
+ }
91
+
92
+ const theme = resolveTheme({}, values.preset);
21
93
  const story = {
22
94
  url: url.href,
23
95
  displayUrl: url.host,
24
96
  viewport: { width: 1440, height: 810 },
25
97
  initialWait: 700,
26
98
  tail: 1200,
27
- brand: { background: "#070a12", accent: "#6c5ce7" },
28
- steps: [{ action: "wait", ms: 1500 }],
99
+ brand: { preset: theme.preset, background: theme.background, accent: theme.accent },
100
+ steps,
29
101
  };
30
102
  const outPath = path.resolve(values.out);
31
103
  await mkdir(path.dirname(outPath), { recursive: true });
@@ -39,7 +111,9 @@ export async function init(argv) {
39
111
  }
40
112
 
41
113
  reporter.log(`Created story: ${outPath}`);
42
- reporter.log("The starter records a static page. Use plan to find controls, then add click/type steps.");
114
+ if (!values.auto) {
115
+ reporter.log("The starter records a static page. Use plan to find controls, then add click/type steps.");
116
+ }
43
117
  reporter.log("Run record with this config, then render the resulting record.json.");
44
118
  await reporter.success({ artifacts: [{ kind: "story", path: outPath }] });
45
119
  return outPath;
@@ -1,11 +1,47 @@
1
+ import { existsSync } from "node:fs";
2
+ import { chmod, copyFile, mkdir } from "node:fs/promises";
3
+ import path from "node:path";
1
4
  import { chromium, errors } from "playwright";
5
+ import { FFMPEG } from "./ffmpeg.mjs";
6
+ import { VALID_BROWSERS, findSystemBrowser } from "./system-browser.mjs";
2
7
 
3
- export async function launchBrowser({ headless = true, proxy } = {}) {
4
- return chromium.launch({
8
+ export { VALID_BROWSERS, findSystemBrowser };
9
+
10
+ export async function launchBrowser({
11
+ headless = true,
12
+ proxy,
13
+ browser = "auto",
14
+ launch = (opts) => chromium.launch(opts),
15
+ hasBundledChromium = () => existsSync(chromium.executablePath()),
16
+ } = {}) {
17
+ const mode = browser || "auto";
18
+ if (!VALID_BROWSERS.has(mode)) {
19
+ throw new Error(`Unsupported --browser "${mode}". Choose auto, chromium, chrome or msedge.`);
20
+ }
21
+
22
+ const base = {
5
23
  headless,
6
24
  proxy: proxy ? { server: proxy } : undefined,
7
25
  args: ["--disable-blink-features=AutomationControlled"],
8
- });
26
+ };
27
+
28
+ if (mode === "chrome" || mode === "msedge") {
29
+ return launch({ ...base, channel: mode });
30
+ }
31
+
32
+ if (mode === "chromium" || hasBundledChromium()) {
33
+ return launch(base);
34
+ }
35
+
36
+ for (const channel of ["chrome", "msedge"]) {
37
+ try {
38
+ return await launch({ ...base, channel });
39
+ } catch {
40
+ // Continue trying next installed system browser channel.
41
+ }
42
+ }
43
+
44
+ return launch(base);
9
45
  }
10
46
 
11
47
  export async function newContext(browser, options) {
@@ -29,6 +65,32 @@ export async function newContext(browser, options) {
29
65
  return context;
30
66
  }
31
67
 
68
+ export async function openRecordedPage(
69
+ browser,
70
+ contextOptions,
71
+ { ffmpegPath = FFMPEG, makeContext = (opts) => newContext(browser, opts) } = {},
72
+ ) {
73
+ let context = await makeContext(contextOptions);
74
+ try {
75
+ const page = await context.newPage();
76
+ return { context, page };
77
+ } catch (error) {
78
+ const match = /Executable doesn't exist at ([^\r\n]+)/.exec(String(error?.message || ""));
79
+ if (!match || !/Video rendering requires ffmpeg binary/.test(error.message) || !ffmpegPath || !existsSync(ffmpegPath)) {
80
+ await context.close().catch(() => {});
81
+ throw error;
82
+ }
83
+ const targetPath = match[1].trim();
84
+ await context.close().catch(() => {});
85
+ await mkdir(path.dirname(targetPath), { recursive: true });
86
+ await copyFile(ffmpegPath, targetPath);
87
+ await chmod(targetPath, 0o755).catch(() => {});
88
+ context = await makeContext(contextOptions);
89
+ const page = await context.newPage();
90
+ return { context, page };
91
+ }
92
+ }
93
+
32
94
  /**
33
95
  * Draws a fake cursor + click ripple on top of the page, so the recording
34
96
  * looks like a human is using it.
@@ -5,8 +5,13 @@ import { hasCjk } from "./fonts.mjs";
5
5
  const escapeMarkup = (text) => String(text).replace(/&/g, "&amp;")
6
6
  .replace(/</g, "&lt;").replace(/>/g, "&gt;");
7
7
 
8
- export async function createCaptionLayers({ events, durationSec, font, cjkFont, layout, assetsDir }) {
8
+ export async function createCaptionLayers({
9
+ events, durationSec, font, cjkFont, layout, assetsDir,
10
+ theme = { caption: { fg: "white", bg: { r: 11, g: 15, b: 25, alpha: 0.74 } } },
11
+ }) {
9
12
  if (!font) return [];
13
+ const fg = theme?.caption?.fg || "white";
14
+ const bg = theme?.caption?.bg || { r: 11, g: 15, b: 25, alpha: 0.74 };
10
15
  const captions = events.map((event) => ({ text: String(event.caption || ""), start: (event.tEnd ?? event.t) / 1000 }))
11
16
  .filter(({ text, start }) => text.trim() && Number.isFinite(start) && start >= 0 && start < durationSec)
12
17
  .sort((a, b) => a.start - b.start);
@@ -17,7 +22,7 @@ export async function createCaptionLayers({ events, durationSec, font, cjkFont,
17
22
  const end = Math.min(captions[i + 1]?.start ?? durationSec, start + 2.8, durationSec);
18
23
  if (end <= start) continue;
19
24
  const options = {
20
- text: `<span foreground="white">${escapeMarkup(text)}</span>`,
25
+ text: `<span foreground="${fg}">${escapeMarkup(text)}</span>`,
21
26
  font: `sans-serif ${size}`, fontfile: hasCjk(text) ? cjkFont || font : font,
22
27
  width: width - box * 2, align: "centre", rgba: true, wrap: "word-char",
23
28
  };
@@ -31,7 +36,7 @@ export async function createCaptionLayers({ events, durationSec, font, cjkFont,
31
36
  const file = path.join(assetsDir, `caption-${layout.key}-${i}.png`);
32
37
  const info = await sharp({ create: {
33
38
  width: rendered.info.width + box * 2, height: rendered.info.height + box * 2,
34
- channels: 4, background: { r: 11, g: 15, b: 25, alpha: 0.74 },
39
+ channels: 4, background: bg,
35
40
  } }).composite([{ input: rendered.data, top: box, left: box }]).png().toFile(file);
36
41
  layers.push({ file, start, end, x: Math.floor((layout.width - info.width) / 2), y });
37
42
  }
@@ -6,6 +6,9 @@ export const commandOptions = {
6
6
  json: { type: "boolean", default: false },
7
7
  url: { type: "string" },
8
8
  out: { type: "string", default: "demo.json" },
9
+ auto: { type: "boolean", default: false },
10
+ browser: { type: "string", default: "auto" },
11
+ preset: { type: "string" },
9
12
  },
10
13
  plan: {
11
14
  json: { type: "boolean", default: false },
@@ -16,6 +19,7 @@ export const commandOptions = {
16
19
  proxy: { type: "string" },
17
20
  viewport: { type: "string" },
18
21
  headless: { type: "boolean", default: true },
22
+ browser: { type: "string", default: "auto" },
19
23
  },
20
24
  record: {
21
25
  json: { type: "boolean", default: false },
@@ -28,6 +32,7 @@ export const commandOptions = {
28
32
  proxy: { type: "string" },
29
33
  viewport: { type: "string" },
30
34
  headed: { type: "boolean", default: false },
35
+ browser: { type: "string", default: "auto" },
31
36
  },
32
37
  render: {
33
38
  json: { type: "boolean", default: false },
@@ -38,8 +43,10 @@ export const commandOptions = {
38
43
  "no-captions": { type: "boolean", default: false },
39
44
  vertical: { type: "boolean", default: false },
40
45
  zoom: { type: "string", default: "1.28" },
46
+ "vertical-zoom": { type: "string" },
41
47
  "zoom-duration": { type: "string" },
42
48
  "poster-at": { type: "string" },
49
+ preset: { type: "string" },
43
50
  },
44
51
  serve: {
45
52
  port: { type: "string", default: "4173" },
@@ -49,6 +56,8 @@ export const commandOptions = {
49
56
  out: { type: "string", default: "demo" },
50
57
  port: { type: "string", default: "4173" },
51
58
  story: { type: "string", default: "onboarding" },
59
+ browser: { type: "string", default: "auto" },
60
+ preset: { type: "string" },
52
61
  },
53
62
  doctor: { json: { type: "boolean", default: false } },
54
63
  capabilities: { json: { type: "boolean", default: false } },
@@ -0,0 +1,30 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+
4
+ export const VALID_BROWSERS = new Set(["auto", "chromium", "chrome", "msedge"]);
5
+
6
+ export function findSystemBrowser({
7
+ exists = existsSync,
8
+ platform = process.platform,
9
+ env = process.env,
10
+ } = {}) {
11
+ const candidates = [];
12
+ if (platform === "win32") {
13
+ const roots = [env.PROGRAMFILES, env["PROGRAMFILES(X86)"], env.LOCALAPPDATA].filter(Boolean);
14
+ for (const root of roots) {
15
+ candidates.push({ channel: "chrome", path: path.join(root, "Google", "Chrome", "Application", "chrome.exe") });
16
+ candidates.push({ channel: "msedge", path: path.join(root, "Microsoft", "Edge", "Application", "msedge.exe") });
17
+ }
18
+ } else if (platform === "darwin") {
19
+ candidates.push({ channel: "chrome", path: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" });
20
+ candidates.push({ channel: "msedge", path: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" });
21
+ } else {
22
+ for (const bin of ["/usr/bin/google-chrome", "/usr/bin/google-chrome-stable", "/opt/google/chrome/chrome"]) {
23
+ candidates.push({ channel: "chrome", path: bin });
24
+ }
25
+ for (const bin of ["/usr/bin/microsoft-edge", "/usr/bin/microsoft-edge-stable"]) {
26
+ candidates.push({ channel: "msedge", path: bin });
27
+ }
28
+ }
29
+ return candidates.find((candidate) => exists(candidate.path)) || null;
30
+ }
@@ -0,0 +1,125 @@
1
+ export const BRAND_PRESETS = {
2
+ midnight: {
3
+ preset: "midnight",
4
+ background: "#070a12",
5
+ accent: "#6c5ce7",
6
+ light: false,
7
+ frame: {
8
+ bar: "#0D1117",
9
+ border: "#2A3140",
10
+ divider: "#202634",
11
+ addressBg: "#161B23",
12
+ addressBorder: "#262D3A",
13
+ addressText: "#8A93A6",
14
+ shadowAlpha: 0.45,
15
+ edgeOpacity: 0.04,
16
+ },
17
+ caption: {
18
+ fg: "white",
19
+ bg: { r: 11, g: 15, b: 25, alpha: 0.74 },
20
+ },
21
+ chrome: {
22
+ text: "0xE9EDF5",
23
+ muted: "0x8A93A6",
24
+ watermark: "0x5D6678",
25
+ ctaText: "0xFFFFFF",
26
+ badgeBoxAlpha: 0.22,
27
+ },
28
+ },
29
+ daylight: {
30
+ preset: "daylight",
31
+ background: "#f4f6fb",
32
+ accent: "#2563eb",
33
+ light: true,
34
+ frame: {
35
+ bar: "#FFFFFF",
36
+ border: "#D7DFEA",
37
+ divider: "#E6ECF4",
38
+ addressBg: "#F1F5F9",
39
+ addressBorder: "#DCE3EE",
40
+ addressText: "#475569",
41
+ shadowAlpha: 0.16,
42
+ edgeOpacity: 0.6,
43
+ },
44
+ caption: {
45
+ fg: "#0F172A",
46
+ bg: { r: 255, g: 255, b: 255, alpha: 0.92 },
47
+ },
48
+ chrome: {
49
+ text: "0x0F172A",
50
+ muted: "0x475569",
51
+ watermark: "0x64748B",
52
+ ctaText: "0xFFFFFF",
53
+ badgeBoxAlpha: 0.14,
54
+ },
55
+ },
56
+ paper: {
57
+ preset: "paper",
58
+ background: "#f7f3eb",
59
+ accent: "#b45309",
60
+ light: true,
61
+ frame: {
62
+ bar: "#FFFDF9",
63
+ border: "#E4D8C6",
64
+ divider: "#EFE6D8",
65
+ addressBg: "#F5EFE4",
66
+ addressBorder: "#E5D8C5",
67
+ addressText: "#6B5B4B",
68
+ shadowAlpha: 0.15,
69
+ edgeOpacity: 0.55,
70
+ },
71
+ caption: {
72
+ fg: "#292018",
73
+ bg: { r: 255, g: 252, b: 245, alpha: 0.92 },
74
+ },
75
+ chrome: {
76
+ text: "0x292018",
77
+ muted: "0x6B5B4B",
78
+ watermark: "0x8C7B6A",
79
+ ctaText: "0xFFFFFF",
80
+ badgeBoxAlpha: 0.14,
81
+ },
82
+ },
83
+ slate: {
84
+ preset: "slate",
85
+ background: "#0f172a",
86
+ accent: "#10b981",
87
+ light: false,
88
+ frame: {
89
+ bar: "#131C31",
90
+ border: "#2B3954",
91
+ divider: "#222E46",
92
+ addressBg: "#1A253D",
93
+ addressBorder: "#30405E",
94
+ addressText: "#94A3B8",
95
+ shadowAlpha: 0.42,
96
+ edgeOpacity: 0.05,
97
+ },
98
+ caption: {
99
+ fg: "white",
100
+ bg: { r: 15, g: 23, b: 42, alpha: 0.8 },
101
+ },
102
+ chrome: {
103
+ text: "0xF1F5F9",
104
+ muted: "0x94A3B8",
105
+ watermark: "0x64748B",
106
+ ctaText: "0xFFFFFF",
107
+ badgeBoxAlpha: 0.22,
108
+ },
109
+ },
110
+ };
111
+
112
+ export const PRESET_NAMES = Object.keys(BRAND_PRESETS);
113
+
114
+ export function resolveTheme(brand = {}, overridePreset) {
115
+ const presetName = overridePreset || brand?.preset || "midnight";
116
+ const base = BRAND_PRESETS[presetName];
117
+ if (!base) {
118
+ throw new Error(`Unknown brand preset "${presetName}". Choose ${PRESET_NAMES.join(", ")}.`);
119
+ }
120
+ return {
121
+ ...base,
122
+ background: (!overridePreset && brand?.background) || base.background,
123
+ accent: (!overridePreset && brand?.accent) || base.accent,
124
+ };
125
+ }