Skip to content

Make Service Worker implementation up-to-date #19302

Closed

Description

@CYBAI

As @creativcoder mentioned in #11091, the implementation of Service Worker has changed a lot.
I'd like to create this issue to make the Service Worker implementation up-to-date.

Activity

  1. added
    A-content/dom
    on Nov 20, 2017
  2. added a commit that references this issue on Nov 11, 2018
  3. vimpunk commented on Nov 11, 2018

    @vimpunk
    Contributor

    @CYBAI From the referenced PR it looks like you intend to work on this, but it's not assigned. Does that mean there is a chance to collaborate or would you like to work on this yourself?

  4. CYBAI commented on Nov 12, 2018

    @CYBAI
    MemberAuthor

    @mandreyel Sure! The main goal for this issue is to make the implementation of Service Worker up-to-date. So, my first attempt is to update all the related webidl files. Let's update these webidl files first!

  5. vimpunk commented on Nov 12, 2018

    @vimpunk
    Contributor

    @CYBAI Cool, I'll look into updating some myself this evening, if that's alright!

  6. CYBAI commented on Nov 12, 2018

    @CYBAI
    MemberAuthor

    @mandreyel Great! You can leave a comment to let me know you'd like to work on which one so that I can work on the others 😆

  7. vimpunk commented on Nov 12, 2018

    @vimpunk
    Contributor

    @CYBAI Alright, I will (please do the same)! I'm still reading the spec to get a better grip on the concepts at play here.

  8. added 2 commits that reference this issue on Nov 13, 2018
  9. vimpunk commented on Nov 13, 2018

    @vimpunk
    Contributor

    I'm going to try updating the WebIDL of ServiceWorkerGlobalScope!

  10. added 5 commits that reference this issue on Nov 14, 2018
  11. 9 remaining items

  12. added 3 commits that reference this issue on Dec 9, 2018
  13. self-assigned this
    on Dec 18, 2018
  14. CYBAI commented on Dec 18, 2018

    @CYBAI
    MemberAuthor

    I'll work on the remaining two for updating webidl and see what the next step is.

  15. added 3 commits that reference this issue on Dec 23, 2018
  16. gterzian commented on Jun 3, 2019

    @gterzian
    Member

    FYI there seems to be a huge amount of discussions over at https://github.com/whatwg/fetch/search?q=service+worker&type=Issues with regards to how Service Workers integrate with fetch and the http-cache. Related: #23495

  17. gterzian commented on Jul 18, 2019

    @gterzian
    Member

    One thing I'd like to note and check against other people's view:

    It seems to me that we spawn one "service worker manager" per script-process, running it as a thread on the same process.

    I think this design could be improved on, because service workers are shared per-origin(with one origin potentially having many scopes), and the concept of a script process doesn't map to origin, it maps essentially to domain.

    Also, even same-origin pages do not necessarily run in the same script process, since they can be part of different browsing context groups.

    So, we could certainly share a service worker running in one script-process across all origins running the in the browser, but it seems sub-optimal to run them inside a script-process in that case. For example, what happens when the script process shuts down? In theory service workers should remain available to any other same-origin page running in another script-process, and lastly, I think service workers should even remain available once all script-processes have shut down.

    So, I think an improvement on the design could be for the constellation to keep track of service workers(managers) on a per-origin basis, and run them in their own dedicated process, one per origin(which would be child processes of the constellation, not of script).

    Then, when script requests a service-worker, it would initially be "brokered" by the constellation, which would then make a direct IPC communication possible between a script-process and the requested service-worker.

    The constellation would then also be able to do stuff with service-workers outside of the scope of script, such as forwarding notifications coming from elsewhwere(I understand that's part of the idea of service workers).

    Please let me know what you think.

  18. CYBAI commented on Jul 18, 2019

    @CYBAI
    MemberAuthor

    we could certainly share a service worker running in one script-process across all origins running the in the browser, but it seems sub-optimal to run them inside a script-process in that case

    this sounds efficient to me.

    In theory service workers should remain available to any other same-origin page running in another script-process

    yes, I think we should be able to reuse the same service worker between different browsing context but same origin?

    Then, when script requests a service-worker, it would initially be "brokered" by the constellation, which would then make a direct IPC communication possible between a script-process and the requested service-worker.
    The constellation would then also be able to do stuff with service-workers outside of the scope of script, such as forwarding notifications coming from elsewhere(I understand that's part of the idea of service workers).
    Please let me know what you think.

    @gterzian Sure! Don't have too much time recently 😓 but I will read the code and share my thought again here! (also read the SharedWorker issue you just opened) Btw, I'm working on #23545 because we'll also need to handle modules for service workers!

  19. gterzian commented on Jul 18, 2019

    @gterzian
    Member

    the same service worker between different browsing context but same origin

    Yes, so the idea is, I think, that every ScriptThread for a given origin should use a single ServiceWorkerGlobalScope.

    I'm reading a bit more through the existing code and there something that surprises me:

    The constellation seems to have only one swmanager_chan, and it's set to a new value each time a sw_manager registers itself. So I in multiprocess Servo, I think this means that each time a new script process is started, a new sw_manager will be registered, at which point it will send it's swmanager_chan to the constellation and effectively overwrite a previous one. So it seems that in multiprocess mode, the process is broken since you'll end-up with only one SW manager in communication with the constellation, and each new script-process will overwrite a previously registered one(from the constellation's perspective).

    In single-process mode a single sw_manager is created on start-up, however it runs all workers in the same process(obviously).

    So my proposal is essentially have only one sw_manager, like is currently done in single-process Servo, but have it run one process per origin, and have all script-threads/processes use that single sw_manager, running one ServiceWorkerGlobalScope per origin(and have that run multiple registration scopes in one thread, or one thread per registration scope?)

  20. gterzian commented on Apr 6, 2020

    @gterzian
    Member

    I think we've ticked all the boxes at #19302 (comment)

    Time to close this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-content/dom

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions