Skip to content
AnswerWell geo Documentation

Research · 6 min read · Answerwell

Native Client to WebAssembly Migration: PPAPI Mapping, Emscripten, and Web APIs

How to move from Pepper (PPAPI) and the NaCl SDK to WebAssembly with Emscripten, and which Web platform APIs replace each PPAPI surface.

This page summarises Chrome’s WebAssembly migration guidance for applications that today run as Portable Native Client (PNaCl) or Native Client (NaCl) modules using Pepper Plugin APIs (PPAPI). The recommended path is Emscripten plus standard Web APIs; a separate note on compiling C and C++ to WebAssembly with Emscripten applies to how you build and link native code.

When to choose Emscripten over the NaCl SDK

Section titled “When to choose Emscripten over the NaCl SDK”

For most former (P)NaCl use cases, Chrome’s documentation recommends moving from the NaCl SDK to Emscripten.

For the majority of (P)NaCl uses cases we recommend transitioning from the NaCl SDK to Emscripten. Migration is likely to be reasonably straightforward if your application is portable to Linux, uses SDL, or POSIX APIs. While direct support for NaCl / Pepper APIs in not available, we’ve attempted to list Web API equivalents. For more challenging porting cases, please reach out on native-client-discuss@googlegroups.com

— Chrome, WebAssembly Migration Guide

Porting tends to be straightforward when the codebase already targets Linux, SDL, or POSIX. There is no drop-in PPAPI layer in Emscripten; you replace Pepper calls with Web platform APIs, Emscripten shims (SDL, html5.h, filesystem support), or JavaScript glue via embind.

Chrome documents PPAPI-to-Web migration as a status table per Pepper interface: each PPAPI method is paired with the closest Emscripten option, the Web API substitute, and documented limitations.

We’ve outlined here the status of Web Platform substitutes for each of the APIs exposed to (P)NaCl. Additionally, the table lists the library or option in Emscripten that offers the closest substitute.

— Chrome, WebAssembly Migration Guide

Legend used throughout the official tables:

Label Meaning
SDL SDL port layer in Emscripten
FS Emscripten virtual filesystem (partial for some file flows)
GAP No close equivalent; custom code or a future Web API
embind Expose or call JavaScript from C++
OpenGLES Maps toward WebGL / WebGL 2.0
html5.h Emscripten HTML5 helpers (e.g. fullscreen)
utime Timing helpers such as new Date().getTime()

The full per-method tables live in the API Migration section of the migration guide. The sections below group the patterns you need when planning a port—not every Pepper method.

Graphics and input: canvas, WebGL, and events

Section titled “Graphics and input: canvas, WebGL, and events”

2D graphics (PPB_Graphics2D, PPB_ImageData) map cleanly to Canvas and CanvasRenderingContext2D: creation, putImageData, transforms, and ImageData buffers align with SDL-backed ports. Scrolling and some flush semantics are GAP or partial—you may need drawImage on the canvas itself or OffscreenCanvas with ImageBitmapRenderingContext where Pepper had explicit flush or swap behaviour.

3D graphics (PPB_Graphics3D, PPB_OpenGLES2) align with WebGL: Emscripten exposes OpenGL ES toward WebGL 1.0/2.0. Attribute limits and multisampled framebuffers are largely configurable in WebGL 2.0. SwapBuffers has no direct Web equivalent; drawing implicitly presents at the end of a frame. Listen for webglcontextlost on the canvas where Pepper used Graphics3DContextLost.

Input (PPB_InputEvent and related) maps to DOM events: addEventListener on elements instead of Pepper’s request/clear input APIs. SDL covers mouse, keyboard, wheel, and touch. Wheel tick/page scrolling is only partially reflected in WheelEvent.deltaMode; see UI Events discussion. IME-heavy apps lack full PPB_IMEInputEvent parity; canvas text input may need the Input Method Editor API where marked GAP.

Gamepad, pointer lock, fullscreen use Gamepad.*, requestPointerLock / pointerlockchange, and requestFullscreen via SDL or html5.h, with timestamps as in the Gamepad specification.

PPB Audio paths often use SDL for playback (AudioBufferSourceNode) or GAP for low-latency capture paths that resembled AudioWorkletNode or future AudioDeviceClient. Sample format is a common mismatch: Web Audio historically used 32-bit float where PPAPI often used 16-bit integer samples—the migration guide notes spec work toward 16-bit AudioBuffer support.

MediaStream audio/video tracks map to getUserMedia(), MediaStreamTrack, and constraint APIs. Pepper buffer recycling and frame pull APIs are largely GAP; live streams do not preload the way some NaCl apps expected (Media Capture and Streams). Programmatic video frames may use canvas capture instead of PPB_MediaStreamVideoTrack frame pools.

File I/O and references (PPB_FileIO, PPB_FileRef, PPB_FileSystem) split between Emscripten FS (MEMFS/IDBFS-style workflows) and the Native File System API (chooseFileSystemEntries, FileSystemDirectoryHandle, writers). User-granted directories lack absolute paths and some metadata (creation time, full MIME typing via GAP partial). Rename is multi-step on the Web compared to Pepper.

Networking (PPB_URLLoader, request/response info) is commonly implemented with embind wrapping XMLHttpRequest or the Fetch API. Redirect control, referrer policy, upload/download progress without buffering the whole body, and streaming directly to disk are weaker or GAP compared to Pepper; upload streaming may use fetch upload streaming. PPB_WebSocket maps directly to the WebSocket interface.

Messaging and views use Window.postMessage, MessagePort, getBoundingClientRect, IntersectionObserver, and document.visibilityState instead of PPB_Messaging, PPB_View, and instance callbacks. There is no Web equivalent to registering a NaCl module as a MIME-type handler for the whole document (PPB_Instance / HandleDocumentLoad).

Video codecs and low-level networking gaps

Section titled “Video codecs and low-level networking gaps”

PPB_VideoDecoder, PPB_VideoEncoder, and PPB_VideoFrame are marked GAP relative to Pepper’s pooled-frame model; the migration guide points to the WebCodecs explainer for decode/encode pipelines with different buffer lifecycle semantics.

PPB_HostResolver, PPB_NetAddress, PPB_NetworkList, PPB_NetworkMonitor, and PPB_NetworkProxy have no direct browser equivalents—applications that depended on host resolution, interface lists, or system proxy configuration need a different architecture (typically server-mediated or capabilities exposed only through higher-level fetch/WebSocket APIs).

Data types and threading (PPB_Var*, PPB_Core, message loops)

Section titled “Data types and threading (PPB_Var*, PPB_Core, message loops)”

Arrays, dictionaries, UTF-8 strings, and ArrayBuffer interop map to JavaScript values via embind. Sub-range Map/Unmap on shared buffers outside Wasm linear memory is GAP unless future multiple memories or mapping APIs appear.

PPB_Core timing uses new Date().getTime(); main-thread detection and CallOnMainThread style sync are GAP but can be approximated with workers, postMessage, and Atomics.wait. PPB_MessageLoop is largely moot because workers and the main thread already run event loops.

Emscripten build choices for browser deployment

Section titled “Emscripten build choices for browser deployment”

When moving C/C++ to Wasm, prefer static linking for predictable browser bundles.

Emscripten works best with static libraries (.a). Shared libraries (.so, .dylib, .dll) are less useful in browser deployment and can complicate things unnecessarily.

— Chrome, Compiling C and C++ to WebAssembly with Emscripten

Link POSIX/SDL-friendly code statically; avoid shared-library assumptions carried over from desktop NaCl builds.

  • Treating PPAPI as supported in Emscripten—plan explicit replacements from the official mapping tables.
  • Assuming SwapBuffers or Flush on graphics contexts have Web twins; refactor to implicit presentation or OffscreenCanvas patterns.
  • Using 16-bit audio buffers without converting to float Web Audio buffers where the platform still requires it.
  • Expecting filesystem absolute paths or empty-directory deletes exactly like PPB_FileRef when using permission-gated browser file handles.
  • Relying on synchronous HandleBlockingMessage—use async messaging or worker-side Atomics.wait instead.
  • Shipping dynamic native .so linkage instead of static .a archives for Wasm targets.
  1. Inventory Pepper interfaces your NaCl module actually calls (graphics, audio, file, network, video) and mark each row in Chrome’s API Migration tables as SDL, FS, embind, Web API, or GAP.

  2. Confirm the C/C++ codebase builds with Emscripten using static libraries (.a), following Emscripten WebAssembly guidance.

  3. In a staging build, exercise replaced Web APIs (canvas/WebGL, Fetch/XHR, file picker APIs, WebSocket) and verify GAP items have an acceptable workaround or scope reduction.

  4. For thread-dependent or blocking flows, validate behaviour with your target browser’s WebAssembly thread support and adjust architecture if those APIs remain required.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.