Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Read this first; then `docs/design/sdk-design.md` (Draft v3) for the full archit

---

## 2026-11-23 — system traces: honest window for throttled/frozen tabs and report dialogs
Sweep of the 14 open BWD reports: traces often started mid-window or stopped early. Two causes. (1) Every late-start report had `app_state=background` at report time: a hidden tab stops rAF (fps) and throttles/freezes timers, so neither the 1 Hz polls nor the held-value refresh ran, the store evicted what had been written before the window, and the window head was empty (BWD-13/2/4/7/10/6; BWD-11 = iOS page frozen after 6 s). (2) `code_dialog` reports (BWD-15): the capture is frozen when the dialog OPENS but `manifest.time.end` was the assembly clock at Send, so the range had a 7 s empty tail.
Fix: `CaptureProvider.prepareSnapshot(window)` (optional, core contract) + `CaptureCoordinator.prepareSnapshot` (isolated like start/stop), invoked by the client right before a report snapshot (`openCapture`, window = resolved `Duration`). `SystemTracesProvider` implements it: each producer may `sampleNow()` (browser `MemoryProducer` reads `performance.memory`, still readable when hidden); every HELD trace is re-recorded at the window end ONLY when its last row is at least `refreshMs` old (the refresh timer evidently did not run; a healthy page has a row within `refreshMs` and a twin a few ms before the end was an Electron-integration flake) and carried to the window start with the value in force there (per-trace change history, capped at 64). The carried values are RETURNED from the hook and ride along as report-time extras (`openCapture` merges them), not written: the store trims by a range read from its own clock, which can sit a ms past the window start and would drop a seed stamped exactly there. Polled values (fps, lag) are never carried — a hidden tab's fps stays an honest gap. `bundle-stream-assembler` ends the manifest AND the stream encoders' session (replay/video) at the snapshot range end (never before the newest streamed record, never past the assembly clock; report-time extras don't count). Report-time extras of a non-encoder type that predate the planned start (a carried seed stamped a ms before the store's own range) are copied and clamped up to `plan.start`, payload `timestamp` included, because the viewer drops events before the manifest start. Late-tick catch-up (held refresh on the first tick after a throttled sleep) already existed and is now pinned by a test. Tests: provider, coordinator, client, assembler, browser producer + a coordinator→exporter integration test; mutator loop run (survivors are memory-only/equivalent: stopped-guard, young-session guard, history prune/dedupe/cap).

## 2026-11-23 — replay: inline `<svg>` no longer blocked by default
BWD production reports showed every `<svg>` as an empty box: `MEDIA_SELECTOR` contained `svg`, and `blockAllMedia` (default on) turned each into a size-only placeholder (verified in a real BWD-15 snapshot: all svg nodes childless, only `rr_width`/`rr_height`). `svg` is removed from `MEDIA_SELECTOR` (`packages/replay/src/masking.ts`); the raster-bearing `<image>` stays blocked (rrweb tests the selector per element), svg `<text>` follows the normal text-masking rules, and `blockAllMedia` for img/video/iframe/etc is unchanged. Tests: `masking.test.ts` + `masking.integration.test.ts` (svg recorded at defaults, `<image>` data URI absent). Not verified: the viewer-side replayer (`createElementNS`/`xlink:href`/`<use>`) lives outside this repo.

## 1. What's implemented

### Tier-0 (foundations — no Bugsee dependencies, pure libs)
Expand Down Expand Up @@ -1529,6 +1536,11 @@ Verified against current majors, all green with no adapter code changes: `@bugse

**Follow-up 2 (issue #11).** `sveltekit-e2e` now wires `sveltekit({ preprocess: [componentAnnotatePreprocessor()] })` (the `@bugsee/sveltekit` README Kit 3 call, with the plugin imported by path) and asserts the SSR HTML carries `data-bugsee-component` (mutation-checked: removing `preprocess` fails it). The plugin is imported from its built dist (the e2e builds it first) because Kit 3 re-loads `vite.config.ts` in a plain-Node post-build process that cannot resolve the workspace's extensionless TS source. The README nits were already fixed (#157). Only Rollup 5 (still prerelease, `5.0.0-2` on the `beta` tag) remains open: keep watching.

### App version/build auto-detection gaps (2026-11-23)
**Finding.** `environment.app.version` read `0.0.0` on the BWD dashboard (Angular, esbuild builder, no Bugsee plugin): the browser has no runtime source for the version (no package.json, no env), so it needs a build-time `define` of `__BUGSEE_APP_VERSION__`/`__BUGSEE_APP_BUILD__`. Every other runtime already detected it (core `resolveAppIdentity`; node/bun/electron: `BUGSEE_APP_VERSION`, nearest package.json, Electron `app.getVersion()`; edge: env vars).
**Added.** (1) Node/Bun: when the cwd search finds no version (container `WORKDIR /`, service-manager cwd), the entry script's directory (`Bun.main`, else `process.argv[1]`) is searched next (`entryPoint` seam on `createNodeAppIdentitySource`; never overrides `appRoot` or a cwd hit). (2) Edge/Cloudflare: new `bindings` launch option + `createEdgeAppIdentity(bindings)` reads `BUGSEE_APP_VERSION`/`BUGSEE_APP_BUILD` from the Workers `env` and a `CF_VERSION_METADATA` binding (`tag` = version, `id` = build) since workerd `process.env` is often empty. (3) Browser README: Angular `define` recipe.
**Deliberately not added.** `npm_package_version` (node doc comment: inherited by child processes, wrong in workspaces); generic `<meta name="version">` / PWA manifest guessing (false positives); Angular's `ng-version` (framework version, not the app's).
**Still manual.** Browser and Web/Service Workers without a bundler define or `appVersion`; Cloudflare needs `bindings: env` (or a `BUGSEE_APP_VERSION` var) passed to `launch()`.
### Debug-ID stamping inside the build for Vite, Rollup and Rspack; verified stamps; safe map deletion (2026-11-23)
`@bugsee/bundler-plugin-core` now stamps INSIDE the build wherever the bundler has a pre-write hook, so Subresource Integrity hashes taken later describe the stamped bytes: webpack 5 and **Rspack** at `PROCESS_ASSETS_STAGE_DEV_TOOLING + 1` (shared `tapProcessAssetsStamp`), **Vite and Rollup** in `generateBundle` (`order: 'pre'`; `rollupAssetStore` over chunks + `.map` assets; the stamped id is also put on `chunk.map` because Vite regenerates the map of a lazy-loading chunk after user hooks). esbuild and the standalone CLI stay post-emit with the SRI refusal (its message now names the workaround). Every stamp is verified (`verify-stamp.ts`: parses, sourceMappingURL intact, map debugId matches, original bytes + appended stamp): in-build all-or-nothing, post-emit snapshot + restore of the failing pair (`stamp-files.ts`); an in-build stamp is re-checked on disk (`verifyStampedPairs`) and against the HTML (`findIntegrityMismatches`). `.map` deletion now requires a confirmed upload AND a debugId on the map (`partitionByKeyed`). Real-build proof: `plugin.in-build.real-build.test.ts` (Vite 7 + 8, Rollup, Rspack with its built-in SRI plugin) and a Chromium run in `instrumentation-tests/test/sri-vite-rollup.e2e.ts`. Measured ordering limits and what the guards do not see: `docs/design/source-maps.md` §7.1.

Expand Down
11 changes: 11 additions & 0 deletions packages/browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ await launch('<app-token>', { appVersion: '2.4.1', appBuild: '381' });

Bugsee can also pick them up at build time. The Bugsee Vite and webpack plugins inject the constants `__BUGSEE_APP_VERSION__` and `__BUGSEE_APP_BUILD__` automatically when you give `appVersion` and `appBuild` to the plugin, or when `BUGSEE_APP_VERSION` and `BUGSEE_APP_BUILD` are set in the build environment. You can also define those two constants yourself in your bundler, or set `__BUGSEE_APP_VERSION__` and `__BUGSEE_APP_BUILD__` as globals before launching (for example `window.__BUGSEE_APP_VERSION__ = '2.4.1'`). Options passed to `launch` always win over the build-time values.

**Angular (esbuild `application` builder) and other builds without a Bugsee plugin.** A browser cannot read your `package.json` at runtime, so the version has to be baked in at build time. Angular's builder takes a `define` map in `angular.json` (`projects.<app>.architect.build.options.define`):

```json
"define": {
"__BUGSEE_APP_VERSION__": "\"2.4.1\"",
"__BUGSEE_APP_BUILD__": "\"381\""
}
```

Generate those two lines in CI from your own version and commit id (a small script that writes `angular.json`, or `ng build --configuration` with a configuration-specific `define`). The same two constants work for any bundler that can substitute globals: esbuild and Vite take `define`, webpack uses `DefinePlugin`, and Rollup has no `define` option, so use a replacement plugin such as `@rollup/plugin-replace` (`replace({ preventAssignment: true, values: { __BUGSEE_APP_VERSION__: JSON.stringify('2.4.1'), __BUGSEE_APP_BUILD__: JSON.stringify('381') } })`). Without any of these the report shows `0.0.0` and the SDK warns once in the console.

If no version can be found, Bugsee logs a single warning to the console and reports the version as `0.0.0` and the build as `0`. A page can also declare them in its HTML:

```html
Expand Down
33 changes: 33 additions & 0 deletions packages/browser/src/trace-producers.process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,39 @@ describe('createBrowserSystemTraceProducers: process traces', () => {
}
});

it('the memory producer takes a fresh heap reading on demand (a hidden tab ran no poll) and never invents one', () => {
const memoryInfo = { usedJSHeapSize: 10, totalJSHeapSize: 20, jsHeapSizeLimit: 100 };
const win = Object.assign(mkTarget(), { performance: { memory: memoryInfo, now: () => 1 } });
try {
const memory = createBrowserSystemTraceProducers({
...browserTraceEnvFrom(win, undefined),
window: win,
}).find((p) => p.name === 'memory') as TraceProducer;
const out = start(memory);
out.length = 0; // the baseline
memoryInfo.usedJSHeapSize = 40;
memory.sampleNow?.();
expect(out.map((r) => [r.name, r.value])).toEqual([
['ram_js_heap_total', 100],
['ram_js_heap_free', 60],
['ram_js_heap_used', 40],
]);
expect(out.every((r) => r.hold === false)).toBe(true); // polled, never held
memory.stop();
out.length = 0;
memory.sampleNow?.(); // stopped: nothing is written
expect(out).toEqual([]);
// an engine with no reading (Safari/Firefox) emits nothing
(win.performance as { memory?: unknown }).memory = undefined;
const again = start(memory);
again.length = 0;
memory.sampleNow?.();
expect(again).toEqual([]);
} finally {
resetProcessTracker({ window: win });
}
});

it('all process traces share ONE tracker per window and the env seams reach it (idle + user idle)', async () => {
const win = Object.assign(mkTarget(), {
performance: {
Expand Down
9 changes: 9 additions & 0 deletions packages/browser/src/trace-producers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ export class MemoryProducer extends TraceProducerBase {
this.#off = undefined;
}

/**
* One live reading on demand, right before a report snapshot: a hidden tab throttles (or freezes) the tracker's polling
* timer, but `performance.memory` stays readable, so the report still ends with a real sample. No reading, no emit.
*/
sampleNow(): void {
const cur = this.#tracker.currentHeap();
if (cur !== undefined) this.#publish(cur);
}

#publish(m: HeapState): void {
this.poll(() => {
this.emit(TraceName.RAM_JS_HEAP_TOTAL, m.limit);
Expand Down
Loading
Loading