demo · v147

Worker violation probe

Two dedicated workers, two different Document Policies. Each runs the same probe (sync XHR, oversized image decode, document.write-like sandbox call) and reports whether the policy stopped it. A real consistency check between document- and worker-level enforcement.

Developer trial: Document Policy inside Dedicated Workers ships behind chrome://flags/#enable-experimental-web-platform-features in Chrome 147. The page feature-detects and surfaces what the runtime allows.

The "permissive" worker is created with no extra policy. The "strict" worker is created with Document-Policy: no-unsized-media, no-document-write, sync-xhr=(). Each probe button posts a message to both workers and renders their replies.

Worker · permissive

no policy
new Worker('worker.js'); // baseline

Worker · strict

no-unsized-media · sync-xhr=() · no-document-write
new Worker('worker.js', {
  // chromium spec form
  documentPolicy: 'no-unsized-media, sync-xhr=()'
});

Probe results

How the policy is enforced

  1. Worker script reads self.documentPolicy (new in Chrome 147) to know what's gated.
  2. Probe handlers wrap each restricted operation in try/catch and report violations.
  3. Real enforcement happens in the renderer — strict workers can't even issue a sync-xhr; the call throws synchronously.
// strict worker spinup (Chrome 147+):
const strict = new Worker('worker.js', {
  documentPolicy: 'no-unsized-media, sync-xhr=()'
});

// in the worker:
self.addEventListener('message', (ev) => {
  if (ev.data === 'sync-xhr') {
    try {
      const xhr = new XMLHttpRequest();
      xhr.open('GET', '/data.json', false); // throws under sync-xhr=()
      xhr.send();
      postMessage({ ok: true });
    } catch (e) {
      postMessage({ ok: false, err: e.message });
    }
  }
});

see also

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗