demo · v136
WASM bid round-trip
The bidding-script use case in one page: take an advertiser keyword, encode it with protectedAudience.encodeUtf8, copy into a WebAssembly module's linear memory, run a (trivial) hash function inside, copy bytes back, and decode with protectedAudience.decodeUtf8. The same flow real bidders run thousands of times per auction.
Probing…
Outside a Protected Audience worklet,
protectedAudience.encodeUtf8 is unavailable. This concept falls back to TextEncoder/TextDecoder so you can see the byte flow.
encoded bytes (UTF-8)—
wasm hash output (bytes)—
decoded result—
the code
// inside a Protected Audience generateBid() worklet (Chrome 136+):
const bytes = protectedAudience.encodeUtf8(adKeywords);
new Uint8Array(wasm.exports.memory.buffer).set(bytes, ptr);
wasm.exports.scoreFromKeywords(ptr, bytes.length);
const outBytes = new Uint8Array(wasm.exports.memory.buffer, outPtr, outLen);
const out = protectedAudience.decodeUtf8(outBytes);
why this angle
The sibling concept proves the helpers exist. This concept demonstrates the loop they were designed for: bidding scripts hand strings to wasm scoring kernels and read strings back. Without the helpers, every worklet shipped its own UTF-8 encoder.
see also
- PA text helpers — feature index
- API-surface concept
- ChromeStatus entry
- Protected Audience spec