Skip to content

feat(csr): ship standalone worker file and expose workerUrl option - #412

Open
nicklasl wants to merge 5 commits into
mainfrom
nicklasl/csr-ship-worker-js
Open

feat(csr): ship standalone worker file and expose workerUrl option#412
nicklasl wants to merge 5 commits into
mainfrom
nicklasl/csr-ship-worker-js

Conversation

@nicklasl

@nicklasl nicklasl commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

  • Ship dist/confidence-worker.js as a standalone file customers can copy to their static assets
  • Expose workerUrl on initSessionRecorder for customers whose CSP blocks data: and blob: in worker-src
  • Re-export workerScript from @spotify-confidence/session-recording/worker for server-route integration
  • Add CSP section to the README covering required directives, hosting options, and troubleshooting

Build restructure

The standalone worker file is now a first-class build artifact of csr-common. During csr-common's build, emit-worker-file.mjs extracts the bundled workerScript string from the compiled output and writes it as dist/confidence-worker.js. session-recording simply copies the file from csr-common's dist — no regex parsing, no second rolldown invocation.

Build order:

  1. csr-common prebuild → build-worker.mjs bundles worker source into string constant + generates csr-version.ts
  2. csr-common build → tsdown, then emit-worker-file.mjs writes dist/confidence-worker.js
  3. session-recording build → tsdown, then copies from csr-common/dist/confidence-worker.js

Follow-up (separate PR)

  • Version handshake: tab sends sdkVersion in hello, worker reports workerVersion in welcome, mismatch logs a warning via debugLogger
  • ./worker helper export using new URL pattern for automatic bundler asset handling (needs Next.js validation)

Test plan

  • yarn build:csr produces identical confidence-worker.js in both csr-common and session-recording dist
  • Standalone file is valid JS (13.6KB)
  • workerUrl forwarded from initSessionRecorder to createUploader (unit-tested)
  • @spotify-confidence/session-recording/worker exports workerScript
  • Full CSR test suite passes (136 tests)

🤖 Generated with Claude Code

- Add `workerUrl` to `InitSessionRecorderOptions`, plumbed to
  `createUploader`.
- Export `workerScript` from `@spotify-confidence/session-recording/worker`
  so customers can serve it at a same-origin route.
- Emit `dist/confidence-worker.js` as a standalone file in the npm
  package that can be copied directly to static assets.
- Add CSP section to README with required directives, three hosting
  options (copy, build-tool, serve-from-route), and troubleshooting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicklasl
nicklasl force-pushed the nicklasl/csr-ship-worker-js branch from 04ad1dd to 651317a Compare July 16, 2026 07:31
nicklasl and others added 3 commits July 16, 2026 10:02
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
csr-common now emits dist/confidence-worker.js as a first-class
build artifact. session-recording copies it instead of extracting
the worker string from source.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicklasl
nicklasl force-pushed the nicklasl/csr-ship-worker-js branch from 732ded9 to 0f8148b Compare July 17, 2026 08:40
Comment thread csr/csr-common/scripts/build-worker.mjs Outdated
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant