loadTab

tcmts.cli.test.e2e.prod.loadTab · #sxpzetmb · term · runs anywhere

What a browser tab loads: the page's scripts (its entry and the chunks it preloads), and the server function hash they call. asset is the chunk that calls it: the app's own code.

import { get } from "#codebase/tcmts/cli/test/e2e/prod";

export async function loadTab(url: string) {
  const page = await (await get(url)).text();
  const assets = [...new Set(page.match(/\/_app\/assets\/[^"]+\.js/g) ?? [])];
  const chunks = await Promise.all(
    assets.map(async (a) => ({ asset: a, js: await (await get(new URL(a, url))).text() })),
  );
  const calls = chunks.find((c) => /[`"'][a-z2-7]{52}[`"']/.test(c.js))!;
  return {
    asset: calls.asset,
    assets,
    endpoint: /[`"']([a-z2-7]{52})[`"']/.exec(calls.js)![1]!,
    js: chunks.map((c) => c.js).join("\n"),
  };
}

uses

used by