Part IV — Expert Production Engineering · Chapter 23 · Lesson 4 of 6 · 2 min read
Lesson 4: Browser SDK Integration and Secure Defaults
Lesson level: Expert
Purpose: The minimal SDK performs fetching and instantiation. Secure admission, policy enforcement, UI safety, and usable execution remain explicit integration responsibilities.
Learning Objectives
- Use the verified command or SDK surface.
- Separate artifact validity from runtime availability.
- Record trust checks and safe failure behavior.
4.1 Concepts
The browser-sdk package exports loadPeaWasm(url, imports={}), which fetches bytes and invokes WebAssembly.instantiate. The source helper does not validate HTTP status, source allowlists, digest, ABI, policy, byte-size bounds, or expected executable exports. Treat it as a minimal loader primitive. The TypeScript/React HTTP client integration from Chapter 15 is separate and can invoke a server runtime; it is not offline native WASM execution.
4.2 Annotated Example
Conceptual host sequence: fetch an approved same-origin artifact; bound and verify its bytes; inspect the manifest; allow only approved imports; instantiate; check real exported functions; then enable the UI only if the selected execution path is supported. These checks are application work, not additional arguments supported by loadPeaWasm. Validate UI schemas before rendering; the shipped validator supports text, button, and stack nodes, not arbitrary HTML.
4.3 Guided Practice
Explain the UI state for fetch failure, invalid digest, unsupported ABI, empty native exports, and successful server-backed invocation. Distinguish a networked demo from an offline one.
4.4 Common Mistakes
Do not claim remote invocation works offline, insert arbitrary returned markup, expose broad imported host functions, or hide unavailable execution behind fabricated results.
4.5 Hands-On Lab
- Load a harmless packaging artifact from an approved test origin.
- Inspect actual exports and display an accurate support state.
- Reject unapproved imports and invalid UI node types in the host adapter.
- If using server-backed execution, record the server identity, authentication, and required network connection.
Deliverable: Tested integration, artifact identities, support states, and safe error evidence.
4.6 Review Questions
What validations are absent from the SDK helper? Why is a TypeScript runtime client different from a browser VM? Which UI nodes are supported?
4.7 Applied Challenge
Create a browser adapter with bounded loading, explicit trust checks, safe rendering, and a documented server-backed fallback that never masquerades as offline execution.
Lesson Summary
The minimal SDK performs fetching and instantiation. Secure admission, policy enforcement, UI safety, and usable execution remain explicit integration responsibilities.
Lesson status: Draft complete; ready for review. Source-checked, not browser-execution validated.