v157 · javascript · service workers

Global-scope probe

A window-side typeof ProgressEvent proves nothing here — the interface has always existed on Window. The only honest test registers a real service worker, asks it to look at its own global, and reports what came back over postMessage.

Checking service worker support…

Run the probe

This registers a service worker scoped to this page’s directory only. It has no fetch handler, so it cannot affect anything you load. Unregister it when you are done.

Not run yet.

Window versus service worker

The same construction, attempted in both realms. The gap this feature closes is visible as a difference between these two cards.

Window

Not probed yet.

ServiceWorkerGlobalScope

Not probed yet.

what the worker runs

// inside sw.js
const exposed = typeof self.ProgressEvent === "function";

let fields = null;
if (exposed) {
  const event = new self.ProgressEvent("progress", {
    lengthComputable: true,
    loaded: 512,
    total: 2048,
  });
  fields = {
    lengthComputable: event.lengthComputable,
    loaded: event.loaded,
    total: event.total,
  };
}

port.postMessage({ exposed, fields });

Note that the event itself cannot be posted — an Event is not structured-cloneable — so the worker sends its field values. That is a property of postMessage, not a limitation of the feature: the point is that the worker can build a platform-defined ProgressEvent to read those values from, instead of an object it invented.

see also