demo · v135

Nested srcdoc SW inheritance

Chrome 135 makes <iframe srcdoc> documents real service worker clients that inherit the parent’s controller. But how deep does it go? This demo probes a three-level hierarchy: the top page, a srcdoc iframe (depth 1), and a srcdoc-inside-srcdoc (depth 2). All three should report the same SW controller.

Service Worker: ? v135 behaviour: ?

Depth 0 — top page

waiting…

Depth 1 — srcdoc iframe

waiting…

Depth 2 — srcdoc-in-srcdoc

waiting…

Click the buttons above in order.

what v135 changed

Before Chrome 135, a srcdoc iframe was not treated as a service worker client because it has no URL of its own. Chrome 135 added a rule: a srcdoc iframe inherits its parent’s SW controller at creation time. This probe extends the same question to depth 2: a srcdoc iframe that itself hosts another srcdoc iframe.

/* Depth-1 srcdoc content */
const d1 = `
  <script>
    const ctrl = navigator.serviceWorker.controller;
    // Spin up depth-2 frame
    const f2 = document.createElement('iframe');
    f2.srcdoc = \`<script>
      parent.parent.postMessage(
        {depth:2, ctrl: navigator.serviceWorker.controller?.scriptURL},
        '*');
    <\/script>\`;
    document.body.appendChild(f2);
    parent.postMessage({depth:1, ctrl: ctrl?.scriptURL}, '*');
  <\/script>
`;
frame1.srcdoc = d1;

see also