Skip to content

Route connected web resources through controlling Service Workers #308

Closed
1 of 1 issue completed
Closed

Description

@wieslawsoltes

Parent resource issue: #266
Nested-webview epic: #264
Related CSS URL decoding: #286

Proven gap

Merged #303/#304 route explicit Window.fetch() through the claimed Service Worker, but parser and DOM connected-resource loads still call the host text loader directly. <script src>, <link rel="stylesheet">, <img src>, and CSS image loads therefore bypass the controlling worker. Unchanged VS Code's webview prelude supplies its extension script, styles, and images through the v6 Service Worker broker, so explicit-fetch success cannot render Markdown content.

The generic owner is WebScene's connected-resource/request scheduling. CSS escape decoding remains #286 and CSS cascade work remains under #235.

Scope

  • Route same-scope parser and dynamically connected script, stylesheet, image, and CSS image requests through the active controller before any host fallback/cache read.
  • Preserve browser task ordering: script execution then load/error, stylesheet application then load/error, image decode/currentSrc/natural size then load/error.
  • Carry GET URL, origin/referrer, credentials/cookie policy, destination, client identity, and navigation generation into FetchEvent.
  • Keep interception asynchronous so a Service Worker may message its controlled client for bytes without blocking that client's task queue.
  • Fall through only when FetchEvent is not handled. A handled rejection, timeout, malformed/oversized body, non-success status, retired generation, or stopped worker must fail closed and must not reach the host loader.
  • Keep data/blob/object URLs and service-worker bootstrap loading on their existing appropriate paths.

Acceptance

Proposed focused PR

One generic asynchronous connected-resource interception tranche with native/browser contracts and bounded lifecycle/performance evidence. Keep #266 open for HTTP 200/206/304/range/validator security and cumulative product completion.

Activity

  1. wieslawsoltes commented on Sep 17, 2026

    @wieslawsoltes
    CollaboratorAuthor

    First implementation slice published

    #310 at source head 3f662378 implements the smallest complete asynchronous connected-element tranche:

    • controller-first routing for dynamically connected script, stylesheet, and image requests;
    • Request.destination propagation and client-generation ownership;
    • unhandled host fallthrough, with handled rejection/status/timeout/retirement staying fail closed;
    • runtime wakeup on worker settlement and pending-promise retirement on navigation;
    • browser load/error dispatch and the existing 32-request / 64 MiB response bounds.

    Evidence on exact main 26431500:

    • native WPT-derived contract: 1/1 document, 3/3 subtests, 87 ms;
    • Chrome 153 oracle: 3/3, 63 ms;
    • native 100-cycle script/style/image gate: p95 0.125 ms, heap 1,161,360 -> 1,161,360 bytes, RSS 38,289,408 -> 49,184,768 bytes;
    • a never-settling controlled image retires across navigation in 67.4 ms;
    • snapshot/native build, packaged-Node bootstrap syntax, 3/3 portable-literal tests, prior FetchEvent/CacheStorage/TransformStream gates, and 100-cycle Service Worker lifecycle pass.

    This does not close #308. Initial navigation/parser-blocking styles and scripts, nested frame hydration resources, and CSS url() image requests remain. They require their own asynchronous state-machine integration; CSS escape decoding remains #286. Exact unchanged Markdown acceptance remains cumulative in #266.

  2. wieslawsoltes commented on Sep 17, 2026

    @wieslawsoltes
    CollaboratorAuthor

    Final connected-resource slice published

    PR #337 at source head 466d7b79 completes the remaining #308 CSS-image and cumulative Markdown-preview scope on exact main 5d869353.

    • CSS url() images use the existing asynchronous controlled-resource queue with destination=image.
    • Only unhandled FetchEvents fall through; handled failures and stale replies remain closed.
    • Stylesheet parsing no longer starts a direct host image prefetch while a controller is active.
    • Service Worker client/security identity remains the navigation URL even when authored <base> changes baseURI, fixing the Fix live per-document effective base invalidation #336 regression that broke clients.claim().
    • The copied VS Code 645f29c v6 worker is byte-identical (411abe3177fe8a7fb355bdf310b12b3938d5476e509dd1fb59d5c621ffd5fad0) and the copied README hash is e3194ef2de9a279c774755aefe6ed0598d3b078433513063f3f159175c0f6cc6.

    Focused evidence:

    • native CSS image 100-cycle p95 0.114 ms; heap unchanged at 1,235,032 bytes; peak RSS +10.25 MiB; retained RSS after teardown +8.06 MiB;
    • native WPT contract 1/1 document, 4/4 subtests, 446 ms;
    • Chrome 153 reduced contract p95 18 ms and exact VS Code fixture p95 20.5 ms;
    • Service Worker lifecycle 100-cycle p95 4.852 ms with one-registration high-water;
    • live document/frame base profile passed 4,096 nodes, 81,920 URL lookups, 100 lifecycle cycles, unchanged heap/DOM/wrappers, and bounded RSS.
  3. wieslawsoltes commented on Sep 17, 2026

    @wieslawsoltes
    CollaboratorAuthor

    Final rebased PR head is c3bfde5d1b79812752269a56d7f82a985c2d2af5 on exact main 5d86935319702942b501381de4cefcb6a46d9811.

    Post-amend direct gates:

    • native CSS image/Markdown: 100 cycles, p95 0.189 ms, V8 heap 1,235,032 -> 1,235,032 bytes, peak RSS 38,780,928 -> 49,807,360 bytes, retained RSS 38,780,928 -> 47,448,064 bytes
    • native Service Worker lifecycle: 100 cycles, p95 14.49 ms, registration high-water 1, stable heap
    • nested-frame live base: 81,920 lookups plus 100 lifecycle cycles, state restored, stable heap/nodes/wrappers, RSS +29.5 MiB
    • reduced native WPT: 1/1 document, 4/4 subtests, 112 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vscode-oss/plannedPlanned for the AppScene/WebScene VS Code OSS integration

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions