Bug 227531 - Service worker methods register and update are not working as expected in WKWebView
Summary: Service worker methods register and update are not working as expected in WKW...
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: Other
Hardware: iPhone / iPad iOS 14
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-06-30 08:34 PDT by Kiran S
Modified: 2022-04-12 01:30 PDT (History)
9 users (show)

See Also:


Attachments
Screenshots for service worker registration and update error (460.18 KB, application/zip)
2021-06-30 08:34 PDT, Kiran S
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kiran S 2021-06-30 08:34:41 PDT
Created attachment 432597 [details]
Screenshots for service worker registration and update error

Overview

    Currently all app bound domains are not allowed to register a service worker.

    From the observations it seems like there seems to be a limit of 3 service worker per WebView (Not per domain).
    So if there are 5 app bound domains which have service worker. Only the 3 domains loaded first would be able to register their service workers.

    The next registration attempt would fail with the following error.
    "TypeError: Job rejected for non app-bound domain"
    Even though the domain is app bound and doesn't have any previous service worker registrations.

    Also once the limit of 3 is reached it was not possible to update any of the registered service workers as well.

    Note: I saw the ticket where the limitation of 3 service workers was added - https://bugs.webkit.org/show_bug.cgi?id=213601.
    But it was not clear if this was intended for the whole webview since there could be multiple app bound domains and subdomains.
    

Steps to Reproduce

    1. Prepare 4 separate domains or subdomains with service worker support. These should be valid App Bound Domains.
    2. Load each domain one after another and verify service worker registration.
    3. After all the domains are loaded. Try to update any of the existing service worker registrations.

Actual Result

     - The first 3 "navigator.serviceWorker.register" method invocations would successfully register service workers for respective domains.
       The fourth registration attempt fails with the error - "TypeError: Job rejected for non app-bound domain"

     - After the limit of 3 is reached. It was not possible to update any of the registered service workers as well.
       Attempting to do so would also throw the same error - "TypeError: Job rejected for non app-bound domain"

Expected Result

     - navigator.serviceWorker.register would successfully register service worker for a valid app bound domain.

     - ServiceWorkerRegistration.update should update existing service worker registrations. 

Environment

    Device: iPad Mini 4
    OS: iOS 14.7 (18G5042c)

Additional Info

    In our use case there are dynamic subdomains which would need service worker support.
    Currently we register the parent domain as app bound and we are getting service worker support for the targeted domains. 
    But the issue we are facing currently is that the limit of 3 service workers seems to be across all app bound domains.
Comment 1 Chris Dumez 2021-07-01 18:40:44 PDT
App bound domains -> Kate.
Comment 2 Radar WebKit Bug Importer 2021-07-07 08:35:17 PDT
<rdar://problem/80271124>
Comment 3 Kate Cheney 2021-07-13 08:49:21 PDT
Hi, thanks for the report.

(In reply to Kiran S from comment #0)
> Created attachment 432597 [details]
> Screenshots for service worker registration and update error
> 
> Overview
> 
>     Currently all app bound domains are not allowed to register a service
> worker.
> 
>     From the observations it seems like there seems to be a limit of 3
> service worker per WebView (Not per domain).
>     So if there are 5 app bound domains which have service worker. Only the
> 3 domains loaded first would be able to register their service workers.
> 
>     The next registration attempt would fail with the following error.
>     "TypeError: Job rejected for non app-bound domain"
>     Even though the domain is app bound and doesn't have any previous
> service worker registrations.
> 

This is expected, the max number of service workers for any WKWebView using app bound domains is 3.

>     Also once the limit of 3 is reached it was not possible to update any of
> the registered service workers as well.
> 

I would not expect this, and will look into it. 

>     Note: I saw the ticket where the limitation of 3 service workers was
> added - https://bugs.webkit.org/show_bug.cgi?id=213601.
>     But it was not clear if this was intended for the whole webview since
> there could be multiple app bound domains and subdomains.
>     
> 
> Steps to Reproduce
> 
>     1. Prepare 4 separate domains or subdomains with service worker support.
> These should be valid App Bound Domains.
>     2. Load each domain one after another and verify service worker
> registration.
>     3. After all the domains are loaded. Try to update any of the existing
> service worker registrations.
> 
> Actual Result
> 
>      - The first 3 "navigator.serviceWorker.register" method invocations
> would successfully register service workers for respective domains.
>        The fourth registration attempt fails with the error - "TypeError:
> Job rejected for non app-bound domain"
> 
>      - After the limit of 3 is reached. It was not possible to update any of
> the registered service workers as well.
>        Attempting to do so would also throw the same error - "TypeError: Job
> rejected for non app-bound domain"
> 
> Expected Result
> 
>      - navigator.serviceWorker.register would successfully register service
> worker for a valid app bound domain.
> 
>      - ServiceWorkerRegistration.update should update existing service
> worker registrations. 
> 
> Environment
> 
>     Device: iPad Mini 4
>     OS: iOS 14.7 (18G5042c)
> 
> Additional Info
> 
>     In our use case there are dynamic subdomains which would need service
> worker support.
>     Currently we register the parent domain as app bound and we are getting
> service worker support for the targeted domains. 
>     But the issue we are facing currently is that the limit of 3 service
> workers seems to be across all app bound domains.

Thanks for sharing details about your use case. The limit of 3 service workers across all app-bound domains is intended behavior. I'll take a look at the issue you're experiencing trying to update registered workers, as I would not expect that behavior.
Comment 4 Kiran S 2021-07-14 07:40:01 PDT
Hi,

Thanks for the update.

We can manage with the limit of 3 service workers as long as
    - Registered service workers can be unregistered
    - Registered service workers can be updated

Currently unregister is also blocked - https://bugs.webkit.org/show_bug.cgi?id=227524
Comment 7 youenn fablet 2022-04-12 01:30:03 PDT
Closing this bug in favour of https://bugs.webkit.org/show_bug.cgi?id=229554