demo · v139

CSP Worker Error Handler

When CSP blocks a worker script from loading, Chrome v139 fires an error event on the Worker object instead of throwing synchronously from the constructor. Sites can recover gracefully. Click to construct a worker that violates this page's CSP — the demo wraps both behaviours so you see the difference.

Click the button to attempt construction.

v139 behaviour (this browser)

pre-v139 behaviour (simulated)

SecurityError thrown
new Worker() threw synchronously. Site had to wrap in try/catch, no async hook.

the code

// v139 — recoverable:
const w = new Worker("https://blocked.example/work.js");
w.addEventListener("error", (e) => {
  console.log("worker blocked by CSP:", e.message);
  showFallback();
});

// pre-v139 — synchronous throw:
try {
  const w = new Worker("https://blocked.example/work.js");
} catch (e) {
  // SecurityError
  showFallback();
}

see also