Add Register a Service Worker algorithm for use by other specifications - #1848
Add Register a Service Worker algorithm for use by other specifications#1848monica-ch wants to merge 2 commits into
Conversation
c3118de to
d5ba669
Compare
Add a new exported algorithm that other specifications (FedCM, Payment Handler) can call to register a service worker without going through a client-driven flow. The algorithm is a thin wrapper around Create Job and Schedule Job with job type register, taking storage key, script URL, scope URL, worker type, and update via cache mode as inputs. The algorithm is fire-and-forget: no completion or failure signal is delivered to the caller. Because the job's client is null, the resulting job has no referrer, so the same-origin check between script URL and referrer that Register performs is skipped; a Note documents that callers must satisfy the same-origin precondition asserted in step 1. Part of w3c#1846.
d5ba669 to
4656c9e
Compare
|
@yoshisatoyanagisawa CYTAL, thanks! |
| :: None | ||
|
|
||
| 1. Assert: |scriptURL|'s [=url/origin=] and |scopeURL|'s [=url/origin=] are [=same origin=]. | ||
| 1. If the result of running <a>potentially trustworthy origin</a> with |scriptURL|'s [=url/origin=] as the argument is <code>Not Trusted</code>, return. |
There was a problem hiding this comment.
I assume that Start Register (https://w3c.github.io/ServiceWorker/#start-register) does more validation inside. However, such validation looks not implemented here. For example, a scheme is limited to HTTP/HTTPS, a hash will be omitted, etc.
There was a problem hiding this comment.
Addressed in e053de5. I extracted the fragment removal, HTTP/HTTPS scheme check, and encoded-slash path check into a shared Validate and Normalize a Service Worker URL algorithm. Both Start Register and the exported Register a Service Worker algorithm now use it, while Start Register retains its existing TypeError rejection and scope-defaulting behavior.
|
Is it possible to have a common algorithm between an algorithm call via the JavaScript |
Extract script and scope URL validation from Start Register so browser- initiated registration uses the same normalization and rejection rules as the JavaScript registration path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e60256f0-04fc-4a2f-b93c-ca14f2fea252
|
Thanks, @yoshisatoyanagisawa — updated in e053de5. The URL validation and normalization previously embedded in The shared helper operates on a copy of each URL, so the exported algorithm does not mutate URL records owned by its caller. PTAL when you have a chance. |
Part of #1846.
This introduces a new exported algorithm — a stable public surface that external specifications can bind to.
Change
Adds an exported
Register a Service Workeralgorithm so other specifications such as FedCM and Payment Handler can register a service worker without a client-driven flow.It also extracts the URL checks from
Start Registerinto a sharedValidate and Normalize a Service Worker URLalgorithm. Both JavaScript registration and browser-initiated registration now use the same rules:/or\characters.The existing JavaScript behavior is preserved: invalid URLs reject the
register()promise withTypeError, and a missing scope still defaults to the script URL's directory. The exported algorithm is fire-and-forget and returns when validation fails.Exported algorithm
Input: storage key, script URL, scope URL, worker type, and update-via-cache mode
Output: none
The algorithm validates and normalizes the URLs, requires the script and scope to be same-origin, checks that the script origin is potentially trustworthy, creates a register job with a null client and promise, and schedules it.
Because there is no calling service worker client, the algorithm sets the job's referrer to the normalized script URL. This allows the existing
Registersame-origin checks to remain the canonical enforcement point.Adoption implications
(storageKey, scriptURL, scopeURL, workerType, updateViaCache)signature becomes a stability commitment.Related
Request Soft UpdateUnregister Service WorkersPreview | Diff