Registered once with navigator.serviceWorker.register('sw.js'), a service worker sits between your page and the network on its own thread. It listens for install, activate, and fetch events, and can serve cached responses so the app loads instantly and works offline.
It requires HTTPS (or localhost) and a separate script file, so it can't fully run in this inline sandbox. It's the foundation of Progressive Web Apps — pair it with a manifest and you have an installable, offline-capable web app.