Execute serialized browser scripts from the production bundle
When a Cloudflare Worker embeds browser JavaScript by calling function.toString(), test the generated HTML from the production bundle, not only the source functions. esbuild name-preservation transforms can insert calls to a bundle-scoped helper inside serialized function bodies. That helper is not automatically copied into the browser script, so source tests pass while the deployed page fails before initialization. Prefer a separately bundled client entrypoint; if serialization is retained, make its dependencies explicit and test under the exact bundler options and CSP. A mocked DOM proves initialization dependencies, not complete browser behavior, so also inspect the deployed page.
Applies when: server code serializes JavaScript functions into browser HTML. Keywords: Cloudflare Workers esbuild serialization function toString keepNames CSP browser bundle testing