- From: Yoshisato Yanagisawa <notifications@github.com>
- Date: Wed, 01 Oct 2025 00:34:23 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1793@github.com>
yoshisatoyanagisawa created an issue (w3c/ServiceWorker#1793) The Service Worker Static Routing API defines routing rules using a dictionary. This design presents a potential issue for developers. If a rule includes a condition that the user agent does not recognize or support, it may be silently ignored rather than causing a syntax error. This could lead to the rule being applied in unintended situations, creating unpredictable behavior that is difficult to debug. For example, if a developer includes a new or experimental condition in a rule, the rule might be partially applied on browsers that don't support that specific condition, effectively ignoring a critical piece of the intended logic. This behavior makes feature detection and graceful degradation difficult to implement reliably. To address this, I propose the introduction of a mechanism to allow developers to verify which conditions and sources are supported by the user agent. This could be achieved in a few ways: 1. **An API to Enumerate Supported Features**: Introduce a method that returns a list of supported condition and source values. For example: ``` const capabilities = await navigator.serviceWorker.getStaticRoutingCapabilities(); console.log(capabilities.supportedConditions); // ['urlPattern', 'requestMode', ...] console.log(capabilities.supportedSources); // ['fetch', 'cache', ...] ``` 2. **An API to Validate a Rule**: Provide a method that allows developers to check if a set of conditions or sources is supported before adding the rule. This would enable proactive validation. ``` // Returns true if all specified condition keys are supported by the UA. const areConditionsSupported = await navigator.serviceWorker.supportsConditions([ 'requestMethod', 'or', ]); if (areConditionsSupported) { // All conditions are supported, so we can safely add the rule. await registration.routing.addRoutes({ condition: { or: [ { requestMethod: "GET" }, ] }, source: "network" }); } else { // A condition is not supported. Use fallback logic. console.log('A required routing condition is not supported. Using a simpler rule.'); } ``` 3. **A "Required" or "Mandatory" Field in `addRoutes()`**: Add an option to specify that certain conditions are essential for a rule. If a mandatory condition is not supported by the user agent, the `addRoutes()` call would reject, rather than silently ignoring the condition. ``` await registration.routing.addRoutes([{ condition: { or: [ { requestMethod: "GET" } ] }, source: "network" // This would cause the call to fail if `requestMethod` is not supported. requiredConditions: ["requestMethod"] }]); ``` This topic has been previously discussed in https://github.com/WICG/service-worker-static-routing-api/issues/28. -- Reply to this email directly or view it on GitHub: https://github.com/w3c/ServiceWorker/issues/1793 You are receiving this because you are subscribed to this thread. Message ID: <w3c/ServiceWorker/issues/1793@github.com>
Received on Wednesday, 1 October 2025 07:34:26 UTC