llw-livive-net

Browser Reduction Experiment

Date: 2026-12-05
Status: historical experiment; see CONCEPTS.md for the current architecture.
Scope: exploratory test of replacing the Playwright browser path with lighter HTTP/DOM tooling for text extraction.


Context

The existing CI text snapshots come from cp-livive-net/scripts/screenshots.py.

For each view, Playwright:

  1. Launches Chromium headless.
  2. Navigates to the built SPA.
  3. Authenticates through the real login form, with an API-login fallback.
  4. Waits for a view-specific selector.
  5. Captures a full-page PNG.
  6. Runs document.body.innerText and writes a plain-text DOM snapshot.

The text snapshots are written to artifacts/text/*.txt and included in report.md only. index.html and report.pdf remain screenshot-based.

cp-livive-net/scripts/report.py also uses Playwright Chromium to render index.html into report.pdf.

The question for this experiment was not how to replace that script. The goal was to use the existing workflow as a test case for distillation: how much tooling can be removed, and how much output fidelity survives.


Tooling Baseline

Component Approximate installed size
Playwright Chromium 377 MB
Playwright Chromium headless shell 206 MB
happy-dom 18 MB

The Playwright browser cache is roughly 583 MB on this machine. happy-dom is roughly 18 MB after installation.

Environment notes:


Experiment 1: curl / httpx Against the Frontend

Method

Requested the production Vite preview at /login and /admin with curl.

Result

Both routes returned the same SPA shell:

<!doctype html>
<html lang="en">
  <head>
    ...
    <script type="module" crossorigin src="/assets/index-CTKtd__A.js"></script>
    <link rel="stylesheet" crossorigin href="/assets/index-CYu2h78v.css">
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

/login and /admin are byte-for-byte the same shell. The actual page content is produced by React after the JavaScript bundle runs.

Finding

curl, httpx, or any non-JavaScript HTTP client can retrieve the shell, but not the rendered page text. There is no server-side HTML for individual routes.


Experiment 2: lynx

lynx was not installed in the test environment, so it was not run directly.

Its architectural limitation is the same as curl: it does not execute JavaScript. Against this SPA it would receive the same <div id="root"></div> shell.

For this application, a text browser is in the same category as an HTTP client with respect to page text: it cannot produce the innerText snapshots the current workflow records.


Experiment 3: httpx Against the Backend API

Method

Started a seeded backend on a non-default port and drove the API with httpx.

Sequence tested:

POST /auth/login
GET  /auth/me
GET  /jobs
GET  /users?role=customer
GET  /users?role=technician
GET  /jobs/1
GET  /jobs/1/messages
GET  /jobs/1/quote
GET  /jobs/1/invoice

Non-GET requests included X-Requested-With: XMLHttpRequest, matching the frontend CSRF convention.

The backend issues the session cookie as Secure:

Set-Cookie: sid=...; Path=/; HttpOnly; Secure; SameSite=Lax

Over plain http://127.0.0.1, httpx correctly declines to send a Secure cookie. The first authenticated request therefore returned 401.

The workaround used in the experiment was to extract sid from the Set-Cookie header and re-add it as a normal cookie. This is the same class of workaround already present in screenshots.py for Chromium over plain HTTP.

Result

With the cookie re-injected, all requests succeeded:

Endpoint Result
POST /auth/login 200, returned Admin Owner
GET /auth/me 200
GET /jobs 200, 3 jobs
GET /users?role=customer 200, 3 customers
GET /users?role=technician 200, 2 technicians
GET /jobs/1 200, job + customer + technician + messages
GET /jobs/1/messages 200, 4 messages
GET /jobs/1/quote 200, 3 line items, status approved
GET /jobs/1/invoice 200, 3 line items, status draft

Representative response data:

jobs:
  Stair Runner Installation        pending      Client Three / Tech One
  Bedroom Carpet Replacement       scheduled    Client Two / Tech Two
  Living Room & Hallway Carpet     in_progress  Client One / Tech One

job 1:
  address: 123 Maple Street, Springfield
  customer: Client One (client1@cp.livive.net)
  technician: Tech One (tech1@cp.livive.net)

messages:
  Client One  shared    Hi! What time will the installer arrive on Monday?
  Admin Owner shared    Tech One will arrive between 9 and 10am on Monday.
  Admin Owner internal  Subfloor is uneven near the hallway — bring extra padding.
  Tech One    shared    On my way, ETA about 15 minutes.

quote:
  approved
  Carpet — living room   180 sq ft  $3.50
  Carpet — hallway        60 sq ft  $3.50
  Installation labor       1 job    $450.00

invoice:
  draft
  total: $1,290.00

Finding

httpx can reproduce the login sequence, role selection, job/quote/invoice/ message retrieval, and the data shown on the six captured pages.

httpx cannot retrieve the page text itself. To produce text snapshots, the renderer has to be recreated in Python:

That is a parallel implementation of the React view layer. It is feasible, but the fidelity depends on maintaining that second renderer as the UI changes.


Experiment 4: happy-dom Rendering the Real Bundle

Method

Instead of duplicating the view layer, the built Vite bundle was executed in happy-dom:

  1. Start the seeded backend.
  2. Log in once per role with Node fetch.
  3. Create a happy-dom window at the target route.
  4. Stub window.fetch to add the sid cookie and strip the /api prefix.
  5. Evaluate the built JavaScript bundle.
  6. Wait for React to render and fetch data.
  7. Read document.body.innerText / textContent.

The /api prefix has to be stripped because Vite normally proxies /api/* to the backend, while the backend mounts routes at the root.

Result

All six views rendered content:

login
admin-dashboard
admin-job-detail
technician-dashboard
customer-dashboard
customer-quote

Admin dashboard output from the happy-dom run:

cp.livive.net
Admin OwnerAdminBuild reportLog out
Admin dashboard
New Job
TitleAddressDescriptionCustomerSelect customer…
Client One (client1@cp.livive.net)
Client Two (client2@cp.livive.net)
Client Three (client3@cp.livive.net)TechnicianUnassigned
Tech One (tech1@cp.livive.net)
Tech Two (tech2@cp.livive.net)Statuspending
scheduled
in progress
completed
Create job
All jobs
Stair Runner Installation789 Pine Road, Springfield
PendingClient Three · Tech OneDec 5, 2026, 03:30 AM
Bedroom Carpet Replacement456 Oak Avenue, Springfield
ScheduledClient Two · Tech TwoDec 5, 2026, 03:30 AM
Living Room & Hallway Carpet Install123 Maple Street, Springfield
In ProgressClient One · Tech OneDec 5, 2026, 03:30 AM

Fidelity check

A crude token-overlap comparison was run against the existing Playwright text snapshots:

View happy-dom chars saved snapshot chars saved-token coverage
login 146 194 57.9%
admin-dashboard 703 764 63.5%
admin-job-detail 1190 1313 64.5%
technician-dashboard 300 353 67.6%
customer-dashboard 167 214 70.4%
customer-quote 954 1067 69.8%

The metric is crude and understates content fidelity. Observed causes of mismatch:

The rendered content itself was present for all six views.

Harness complexity

Rendering the real bundle without Chromium required:

The test printed all six results, then the Node process remained alive until the command timeout because React’s message polling timer kept the event loop open. A production harness would need explicit window.close() or timer cleanup.

Finding

happy-dom can execute the real application and produce page text without a browser binary. It preserves component structure and avoids duplicating the React templates.

It does not reproduce Chromium’s layout-aware innerText exactly. Some form of DOM walker or normalization would be needed for close parity.


Fidelity Comparison

Approach Login/data workflow Rendered page text Screenshots PDF Browser binary Main source of drift
Playwright Yes Yes, layout-aware innerText Yes Yes Chromium Browser dependency
curl / httpx → frontend No No No No No SPA does not server-render
lynx No No No No No No JavaScript execution
httpx → API Yes Only by recreating React views No No No Parallel view renderer
happy-dom + built bundle Yes Yes, with whitespace differences No No No DOM/layout emulation differences

Findings

  1. The application is a client-rendered SPA. The server returns one HTML shell for every route. HTTP clients and text browsers cannot see page text.

  2. The API is fully accessible without a browser. httpx reproduced the sign-in and data-retrieval sequence after handling the Secure cookie manually.

  3. API access is not equivalent to page text. Text snapshots require the presentation layer: labels, ordering, conditionals, formatting, and role- specific panels.

  4. happy-dom can render the actual bundle without Chromium. Content was present for all six views, and the real React code was exercised.

  5. happy-dom is not a layout engine. Its text output differs from Chromium innerText, especially around inline/block boundaries. Exact parity needs additional normalization.

  6. The browser is still on the critical path for other outputs. Playwright is currently used for screenshots and for rendering report.pdf. Removing it from text extraction alone would not remove it from the CI toolchain.

  7. Size reduction is substantial but not free. The browser cache is roughly 583 MB; happy-dom is roughly 18 MB. The smaller stack trades browser installation for a Node-based DOM harness and its compatibility quirks.

  8. The simplest HTTP path has the largest fidelity cost. httpx needs no JavaScript runtime, but matching the current text output means maintaining a second renderer for the UI.


What Was Not Tested


Artifacts From the Experiment

Temporary prototypes were run outside the repository:

No repository files were changed by the experiment itself. The only file added for this write-up is browser_reduction.md.