-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for 'serviceworkers' member #507
Conversation
</p> | ||
<div class="example"> | ||
<pre class=""> | ||
"serviceworkers": [{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend for this to be "serviceworker": {
or "serviceworkers": [{
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plural as you can have multiple with different scopes. I am writing serviceworkers in one word to follow the naming used with the Link element "serviceworker" (as you can have multiple link elements)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm of the opinion also that there should only be 1 service worker in the manifest. Other service workers should be declared in the document(s) of the app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your own example used plural and an array :-)
Thanks for stepping-up here @kenchris. I was thinking the serviceworkers object should also be added to the example near the top of the document. |
"src": "sw.js", | ||
"scope": "/foo", | ||
"options": {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenchris - Should line 1971 be }]
to match line 1967?
What is the purpose of adding this information? Is it intended that having a SW defined in the manifest would cause the SW to be registered, similar to calling If so it would be good to get this reviewed by some people familiar with SW registration. |
@benfredwells it is just like calling register manually or adding a service worker link tag. Jake already approved this approach. |
Can we make a decision on whether we want just one or multiple service workers in the manifest? @marcoscaceres @jakearchibald I don't care strongly, but I would like to know so that I can change the WIP patch |
Only 1 please. |
@jakearchibald what is your take? |
@kenchris - After discussion with the Edge PM for Service Workers, Ali Alabas (@aliams) and others at MSFT/Edge, we believe a single serviceworker object listed in the web app manifest will address our use cases; but don’t object to having an array of serviceworkers. /cc @marcoscaceres @jakearchibald |
@kenchris thanks for the explanation. SW registration, updating (e.g. if you change the value in the manifest) and removal is complicated and has already had lots of thought put into it. Are you planning on including algorithms for declarative SW registrations, updates and removals in this spec? Maybe it would be better to just have the syntax for the declarations here, and get the SW spec updated to cover the notion of declarative registration in general, and point to that. |
As far as the question about one ServiceWorker{ } or multiple ServiceWorkers[ ], what if we went with one to start and then looked for feedback / push-back from potential implementers? |
I talked to Jake, we will discuss it after the Chrome Dev Summit as he is currently quite busy. I will work on this after than then. |
@kenchris, thanks for the update. Looking forward to @jakearchibald's input here. My position remains we should only have one (does enough work to make sure the application can be launched). |
@kenchris Have you been able to sync with @jakearchibald about one ServiceWorker{ } or multiple ServiceWorkers[ ] ? Summarizing positions:
|
No, didn't get to talk unfortunately. |
(I've sent an email ping to @jakearchibald with @marcoscaceres and @kenchris on CC) |
I'm happy to go with one for simplicity here. Additional SWs can be in the document as @marcoscaceres says, or perhaps even Apologies for the slow reply! |
@marcoscaceres or @kenchris - Since @jakearchibald has given a thumbs-up to one serviceworker{ } would one of you want to modify the PR? |
Yes, I can work on this |
Now I have IPR issues as well, though I am in the Web Platforms WG as indicated by the Repository Manager |
Marked as non-substantive for IPR from ash-nazg. |
@marcoscaceres - Would you want to merge? |
@RobDolinMS not yet :) This is far from done. |
Looking forward to comments from @marcoscaceres :-) |
<p> | ||
The <a><code>serviceworker</code> member</a> represents a service worker | ||
registration. Other service worker registrations can be done, for instance | ||
by a script; if these have different scopes they will be considered separate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably not re-specify the rules that are in the service worker spec; we should reference them.
</p> | ||
<p> | ||
The <a><code>serviceworker</code> member</a> represents a service worker | ||
registration. Other service worker registrations can be done, for instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to registration definition in SW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
with <var>serviceworker</var> and <var>manifest URL</var>. | ||
</li> | ||
<li>If <var>src</var> is <code>undefined</code>, or if the result of | ||
running <a href="https://w3c.github.io/webappsec/specs/powerfulfeatures/#is-origin-trustworthy">Is origin potentially trustworthy</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: throw in this URL in the dependencies section at the bottom of the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't the service worker registration attempt do this for us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, will need to check
<ol> | ||
<li>Let <var>src</var> be the result of running the <a>steps | ||
for processing the <code>src</code> member of a service worker</a> | ||
with <var>serviceworker</var> and <var>manifest URL</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below, you are using let service worker be
thus trashing this one? I don't think we need to send in a service worker here. Just process the members first, then "attempt to register the service worker"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this comment is in the wrong place!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
<p> | ||
The <dfn>steps for processing the <code>serviceworker</code> | ||
member</dfn> are given by the following algorithm. The algorithm | ||
takes a <a>manifest</a> <var>manifest</var> and <a>serviceworker object</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below, you are using let service worker be...
thus trashing this one? I don't think we need to send in a service worker here. Just process the members first, then "attempt to register the service worker"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fixed
<li>If <var>src</var> is <code>undefined</code>, or if the result of | ||
running <a href="https://w3c.github.io/webappsec/specs/powerfulfeatures/#is-origin-trustworthy">Is origin potentially trustworthy</a> | ||
with the origin of <var>src</var> is <code>Not Trusted</code>, return | ||
<code>undefined</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
screwing up the security aspects of the registration is a pretty big error... so we should maybe pass this through and just allow service worker registration to fail (and kill the whole object then)
with the origin of <var>src</var> is <code>Not Trusted</code>, return | ||
<code>undefined</code>. | ||
</li> | ||
<li>Otherwise, let <var>serviceworker</var> be an object with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let <var>serviceworker</var>
might confuse people into thinking this the actual service worker... maybe "Let registration properties
be..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, did something similar
<div class="example"> | ||
In the following example, the web application is listing | ||
a service worker for the <code>/foo</code> scope: | ||
<pre class=""> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: class=example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, needs to be applied elsewhere in the spec
Yes, any help on that is appreciated :-) I will see if I can get junkee to have a look and maybe help me. |
@kenchris, Start Register is a gate function that you can invoke to trigger a Register. Invoking Start Register makes a job and schedules it in the job queue defined in SW. Start Register is also supposed to take care of the security check and parsing the URLs for the given src and scope, etc. Basically, a register request is processed async given a promise (to Start Register). I'm not quite sure, but you might want to invoke Start Register from steps for processing the serviceworker member I guess. Start Register returns nothing but the given promise to it resolves with a This is basically what SW expects for a register request. I think we should look together if any changes are needed while you're working on this PR. |
<ul> | ||
<li>Invoke <a>Start Register</a> with <var>scope</var> and <var>src</var> | ||
members of the <var>service worker registration</var>, a new <var>promise</var>, | ||
null, <a>manifest URL</a>, <code>"classic"</code> and <code>False</code>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SW's RegistrationOptions dictionary has been extended: https://w3c.github.io/ServiceWorker/#dictdef-registrationoptions. I think both "classic"
and "module"
worker types should be covered and also useCache
should be supported to be aligned with other registration paths. (useCache
indicates whether the UA should set the cache mode to "no-cache" or "default" when fetching a service worker script from networks.)
<ul> | ||
<li>Invoke <a>Start Register</a> with <var>scope</var> and <var>src</var> | ||
members of the <var>service worker registration</var>, a new <var>promise</var>, | ||
null, <a>manifest URL</a>, <code>"classic"</code> and <code>False</code>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the client param to Start Register, I think the browsing context's Document's relevant settings object should be passed instead of null. The given client is used to queue a task later to manipulate promise settlement and parse a fetched script resources later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, will look at that tomorrow then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service workers expect default values from scope, type, and use_cache members. Please see the comments.
property to be <var>type</var>. | ||
</li> | ||
<li>If <var>type</var> is <code>undefined</code> abort these steps and | ||
return <code>undefined</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service workers expect a default value for type member. If type is undefined here, please set the default value to "classic" when passing it to Start Register.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is set in the sub algorithm. Undefined here means that the sub algorithm didn't get a valid value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. I saw you return "classic" when no value is given. It looks good.
property to be <var>use cache</var>. | ||
</li> | ||
<li>If <var>use cache</var> is <code>undefined</code> abort these steps | ||
and return <code>undefined</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, If use_cache is undefined here, please set the default value to false when passing it to Start Register.
- Note that there's an ongoing discussion about the expected default behavior in consider fetching service worker scripts with no-cache by default ServiceWorker#893. So, there's a chance SW may require true as default depending on the discussion there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, ok Please keep me up to date :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. I saw you return false when no value is given. It looks good.
</li> | ||
<li>Set <var>registration</var>'s <code>src</code> property to be | ||
<var>src</var>. | ||
</li> | ||
<li>Let <var>type</var> be the result of running the <a>steps | ||
<li>Let <var>scope</var> be the result of running the <a>steps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to type and use_cache, SW expects a default value for scope too. If scope is undefined, please give null to Start Register as a default value. That makes Start Register set the scope to the same location as the given script url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the value is undefined here, it means that there was a parsing error (check sub algorithms), and I thus don't attempt to register at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood the intention. Please check if it actually doesn't attempt to register in that case (i.e. when the sub algorithm returns undefined.) I left a comment here: #507 (comment).
<var>src</var>. | ||
</li> | ||
<li>Let <var>scope</var> be the result of running the <a>steps | ||
for processing the <code>scope</code> member of a service worker</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this algorithm returns undefined, the steps to install the web application gets to pass nothing to Start Register. In this case, shouldn't there be an error handling such that Start Register is not invoked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check that, it should not be invoked no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<li>If <a>obtaining the manifest</a> succeeds, and the
<var>service worker registration</var> of <a>manifest</a> is not
<code>undefined</code>, a user agent can at this point...
It is not invoked if it fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good.
<li>Return <code>undefined</code>. | ||
</li> | ||
</ol> | ||
<li>Return <var>type</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the return value be value.[[Value]] instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah.. I got it. It has to do with the prefix ! for an ECMAScript abstract operation. So, the value here is the actual value for this member already. But then it still needs to return value instead of type. Referring to other cases, it should return Trim(value) here I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, fixed
<li>Otherwise, return False</li> | ||
</ol> | ||
</li> | ||
<li>Return <var>use_cache</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the return value be value.[[Value]] instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it should return value here. See "steps for processing the prefer_related_applications member" as an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct
@kenchris, when the above comments are addressed, I think the shape of the hooks between Web App Manifest and Service Workers would be OK. For the details of the spec language here, I defer to you and @marcoscaceres. I'll continue to help, of course. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I missed it, but did you also add processing the manifest member to: https://www.w3.org/TR/appmanifest/#processing
members of the <var>registration</var>, | ||
</li> | ||
</ol> | ||
in which case the state of the settled <var>promise</var> determine whether the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: determines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
<code>Document</code>'s | ||
<a href="https://html.spec.whatwg.org/multipage/webappapis.html#relevant-settings-object"> | ||
relevant settings object</a>, or <code>null</code> if unavailable. | ||
<li>Invoke <a>Start Register</a> with <var>scope</var> and <var>src</var> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: should this be "Let registration be the result of Start Registration".
The way this is spec'ed is a bit strange - I was expecting some kind of flow with the resulting promise... but it all seems to magically result in a registration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how to best solve this. Maybe you could solve in a follow up?
</h3> | ||
<p> | ||
The <dfn><code>serviceworker</code> member</dfn> describes a | ||
service worker as defined in [[!SERVICE-WORKERS-1]]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Is there some unversioned reference we can use here instead of V1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not as far as I could see. @jungkees ?
<p> | ||
The <a><code>serviceworker</code> member</a> represents a <a | ||
href="https://w3c.github.io/ServiceWorker/#service-worker-registration-concept"> | ||
service worker registration</a>. Other service worker registrations can be done, for instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text "Other service worker registrations can be done" should be in a non-normative note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you are redefining the rules - which is a bit dangerous. That should point to the SW spec, like:
"For rules on how SWs interact, then see section X of Service Workers"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it a note now. @jungkees can you point me to the best place to refer to?
The <dfn>steps for processing the <code>serviceworker</code> | ||
member</dfn> are given by the following algorithm. The algorithm | ||
takes a <a>manifest</a> <var>manifest</var>. This algorithm returns a | ||
registration object <var>registration</var>, which can be <code>undefined</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: link to registration object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
<p> | ||
The <dfn data-lt="serviceworker-scope"><code>scope</code> member</dfn> of a | ||
<a>serviceworker object</a> is the service worker's associated | ||
<a href="https://w3c.github.io/ServiceWorker/#dfn-scope-url">scope URL</a>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, scope URL should be defined at the end of the document, so not to include the link to the SW spec here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
service worker</dfn> are given by the following algorithm. The algorithm takes | ||
a <a>serviceworker object</a> <var>registration</var>, and a <a>URL</a> <var>manifest | ||
URL</var>, which is the <a>URL</a> from which the | ||
<var>manifest</var> was fetched. This algorithm will return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... what if the manifest redirected during fetch... we might need to clarify that somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help with that? :-)
</li> | ||
<li>If <a>Trim</a>(value) is the empty string, then: | ||
<ol> | ||
<li>Issue a developer warning that the type is unsupported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems odd... you are returning undefined here, but "classic" above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I.e., should we recover to "classic" in error cases for backwards compat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is how it works for Link element. What do you think @jungkees ?
<li>Return <code>undefined</code>. | ||
</li> | ||
</ol> | ||
<li>Otherwise, <a>Trim</a>(<var>value</var>) and return the result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, should should this be restricted to just "classic" and "module"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, "classic", "module" or undefined. Everything else should fail the whole registration as it does with link element
developer warning that the type is unsupported and | ||
return <code>undefined</code>. | ||
</li> | ||
<li>Otherwise, return False</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: return <code>false</code>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
Yes, I did |
So I can go ahead and merge? |
Yeah, why not :) ship it
… On 17 Jan 2017, at 9:04 pm, Kenneth Rohde Christiansen ***@***.***> wrote:
So I can go ahead and merge?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
If I understand correctly, the service worker declaration inside the manifest has no consequence unless the web app is installed without directly visting the web app url.(with an web app store ?) I ask because I have an app where the service worker is only installed after the users checks the checkbox USE OFFLINE. I don't want the manifest to install the service worker on normal page load without user consent first. I came here because https://www.w3.org/TR/appmanifest/#serviceworker-member words are confusing. |
@GrosSacASac, moved your issue here: #640 so we don't lose track of it. |
First attempt at fixing #161
Where do we add the actual registration steps?