trace-avatar-render 0.2.2 → 0.2.4

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,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.4
4
+
5
+ - `reroute` (in `direct()` and a campaign's `app`): addresses answered by others while filming, with the address bar unchanged, e.g. `{ "https://api.example.com": "https://demo-api.example.com" }` films a live front end against a demo API. Pages and API calls alike; redirects are followed inside (a redirect handed to the browser would reach the real address). Only what the browser fetches is rerouted. `rerouted(url, map)` is exported.
6
+
7
+ ## 0.2.3
8
+
9
+ - A director that fails leaves a screenshot of the page it was on: `failShot` in `direct()`; campaigns write `<out>/<render>.failed.png` (and remove a stale one when the render is made again).
10
+
3
11
  ## 0.2.2
4
12
 
5
13
  - A director card that shows the product's address (`card(title, { url: true })`) now records its caption with
@@ -2365,6 +2365,39 @@ async function routeAlias(context, alias) {
2365
2365
  await context.route(`${alias.url}/**`, forward(alias.local));
2366
2366
  if (alias.localApi) await context.route(`${alias.api}/**`, forward(alias.localApi));
2367
2367
  }
2368
+ function originOf(u, what) {
2369
+ let x;
2370
+ try {
2371
+ x = new URL(u);
2372
+ } catch {
2373
+ throw new Error(`reroute: ${what} ${u} isn't an address`);
2374
+ }
2375
+ if (!/^https?:$/.test(x.protocol) || x.pathname !== "/" && x.pathname !== "" || x.search || x.hash) throw new Error(`reroute: ${what} ${u} is an address without a path (https://host)`);
2376
+ return x.origin;
2377
+ }
2378
+ function rerouted(url, map) {
2379
+ let u;
2380
+ try {
2381
+ u = new URL(url);
2382
+ } catch {
2383
+ return null;
2384
+ }
2385
+ for (const [from, to] of Object.entries(map)) {
2386
+ if (u.origin === originOf(from, "from")) return `${originOf(to, "to")}${u.pathname}${u.search}`;
2387
+ }
2388
+ return null;
2389
+ }
2390
+ async function routeReroute(context, map) {
2391
+ for (const [from, to] of Object.entries(map)) {
2392
+ const origin = originOf(from, "from");
2393
+ originOf(to, "to");
2394
+ await context.route(`${origin}/**`, async (route) => {
2395
+ const target = rerouted(route.request().url(), map);
2396
+ const response = await route.fetch({ url: target });
2397
+ await route.fulfill({ response });
2398
+ });
2399
+ }
2400
+ }
2368
2401
  async function routeFolders(context, base2, routes) {
2369
2402
  for (const [prefix, dir] of Object.entries(routes)) {
2370
2403
  const root = resolve4(dir);
@@ -2431,6 +2464,7 @@ async function direct(o) {
2431
2464
  ...state ? { storageState: state } : {}
2432
2465
  });
2433
2466
  await routeAlias(context2, alias);
2467
+ if (o.reroute) await routeReroute(context2, o.reroute);
2434
2468
  if (o.routes) await routeFolders(context2, url, o.routes);
2435
2469
  const page2 = await context2.newPage();
2436
2470
  const cdp2 = await context2.newCDPSession(page2);
@@ -2551,7 +2585,15 @@ async function direct(o) {
2551
2585
  playAt = Date.now();
2552
2586
  events.push({ t: playAt, type: "play", url: path() });
2553
2587
  log(`${id}: playing \u2026`);
2554
- await script(d);
2588
+ try {
2589
+ await script(d);
2590
+ } catch (e) {
2591
+ if (o.failShot) {
2592
+ await d.page.screenshot({ path: o.failShot }).then(() => log(`${id}: the page when it failed: ${o.failShot}`), () => {
2593
+ });
2594
+ }
2595
+ throw e;
2596
+ }
2555
2597
  await sleep3(o.tailMs ?? 800);
2556
2598
  moves.push({ t: Date.now(), ...at });
2557
2599
  await cdp.send("Page.stopScreencast").catch(() => {
@@ -2912,6 +2954,7 @@ async function makeCampaign(c, o = {}) {
2912
2954
  const outBase = join4(c.out, r.id);
2913
2955
  const firstBase = join4(c.out, outs[0].name.replace(/\.[^.]+$/, ""));
2914
2956
  for (const b of [outBase, firstBase]) for (const ext of ["vtt", "chapters.vtt", "png", "scenes.json"]) rmSync3(`${b}.${ext}`, { force: true });
2957
+ rmSync3(join4(c.out, `${r.id}.failed.png`), { force: true });
2915
2958
  const look = c.looks[r.look];
2916
2959
  const script = v.voice?.[r.look];
2917
2960
  const fill = (existsSync5(look.brand) ? brandFile(look.brand).fill : void 0) ?? [];
@@ -2932,6 +2975,7 @@ async function makeCampaign(c, o = {}) {
2932
2975
  url: c.app.url,
2933
2976
  page: v.page ?? "/",
2934
2977
  appName: c.app.name ?? "",
2978
+ failShot: join4(c.out, `${r.id}.failed.png`),
2935
2979
  out: outs.map((x) => ({ file: join4(c.out, x.name), format: x.format, ...x.canvas ? { canvas: x.canvas } : {}, ...x.format === "gif" ? { width: v.width ?? 800 } : {} })),
2936
2980
  look: lookOptions({ title: v.title, endTitle: v.endTitle, polish: r.polish }, look.brand, c.app.name ?? ""),
2937
2981
  ...r.phone ? { viewport: tall ? TALL : { width: 390, height: 844 } } : wide ? { viewport: WIDE } : {},
@@ -2940,6 +2984,7 @@ async function makeCampaign(c, o = {}) {
2940
2984
  ...v.signedIn === false ? { signedOut: true } : {},
2941
2985
  ...c.app.alias ? { alias: c.app.alias } : {},
2942
2986
  ...c.app.routes ? { routes: c.app.routes } : {},
2987
+ ...c.app.reroute ? { reroute: c.app.reroute } : {},
2943
2988
  // `d.app` in the script: the campaign's app, at the address the video shows (its alias, if it has one).
2944
2989
  props: { app: { ...c.app, url: c.app.alias ? `https://${typeof c.app.alias === "string" ? c.app.alias : c.app.alias.host}` : c.app.url } },
2945
2990
  ...speak ? { voice, ...script ? { voiceScript: script } : {} } : {},
@@ -3581,6 +3626,7 @@ export {
3581
3626
  cardCaption,
3582
3627
  cardsOf,
3583
3628
  aliasOf,
3629
+ rerouted,
3584
3630
  direct,
3585
3631
  USAGE,
3586
3632
  parse,
@@ -3602,4 +3648,4 @@ export {
3602
3648
  makeCampaign,
3603
3649
  saysOf
3604
3650
  };
3605
- //# sourceMappingURL=chunk-NFJMQBQ4.js.map
3651
+ //# sourceMappingURL=chunk-7N5RZAMS.js.map