Skip to content

Commit 5d56bb9

Browse files
committed
Change add/remove event listener behavior for service workers
This changes addEventListener() and removeEventListener() to not throw even after the very first evalution of the service worker script. Instead, this specifies user agents have to show a console warning that the asynchronously added listener's event type will not affect service worker's behavior with the functional event stored during the first evaluation. This change referneces the funcional event concept defined in Service Workers spec, and confines the EventTarge object of the specified behavior to ServiceWorkerGlobalScope object instead of all the platform object in the global object. Related SW issue: w3c/ServiceWorker#1004. Related SW PR: w3c/ServiceWorker#1322. Fixes whatwg#371.
1 parent eb0db13 commit 5d56bb9

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

dom.bs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,15 +1062,18 @@ and an <a>event listener</a> <var>listener</var>, run these steps:
10621062

10631063
<ol>
10641064
<li>
1065-
<p>If <var>eventTarget</var>'s <a>relevant global object</a> is a {{ServiceWorkerGlobalScope}}
1066-
object and its associated <a>service worker</a>'s <a for="service worker">script resource</a>'s
1067-
<a for="script resource">has ever been evaluated flag</a> is set, then <a>throw</a> a
1068-
<code>TypeError</code>.
1069-
[[!SERVICE-WORKERS]]
1070-
1071-
<p class="note no-backref">To optimize storing the event types allowed for the service worker and
1072-
to avoid non-deterministic changes to the event listeners, invocation of the method is allowed
1073-
only during the very first evaluation of the service worker script.
1065+
<p>If <var>listener</var> observes a <a>functional event</a>, <var>eventTarget</var> is a
1066+
{{ServiceWorkerGlobalScope}} object, and its associated <a>service worker</a>'s <a for="service
1067+
worker">script resource</a>'s <a for="script resource">has ever been evaluated flag</a> is set,
1068+
then the user agent must show a message on a developer console that the user agent stores the event
1069+
<a for="event listener">type</a> of the <a>functional event</a> for the <a>service worker</a> only
1070+
during the very first evalution of the <a>service worker</a> script, and the asynchronously added
1071+
<a>functional event</a> will not start the <a>service worker</a>. [[!SERVICE-WORKERS]]
1072+
1073+
<p class="note no-backref">To optimize storing the event types allowed for the <a>service
1074+
worker</a>, Service Workers specification does not store the asynchronously added event <a
1075+
for="event listener">type</a>. The <a>event listener</a> will still be added under this condition,
1076+
but the implmentations have to inform developers about this behavior.
10741077

10751078
<li><p>If <var>listener</var>'s <a for="event listener">callback</a> is null, then return.
10761079

@@ -1118,11 +1121,13 @@ and an <a>event listener</a> <var>listener</var>, set <var>listener</var>'s
11181121
method, when invoked, must run these steps:
11191122

11201123
<ol>
1121-
<li><p>If the <a>context object</a>'s <a>relevant global object</a> is a
1122-
{{ServiceWorkerGlobalScope}} object and its associated <a>service worker</a>'s
1123-
<a for="service worker">script resource</a>'s
1124-
<a for="script resource">has ever been evaluated flag</a> is set, then <a>throw</a> a
1125-
<code>TypeError</code>. [[!SERVICE-WORKERS]]
1124+
<li><p>If <var>type</var> is one of the <a>functional events</a>'s <a for="event
1125+
listener">type</a>, the <a>context object</a> is a {{ServiceWorkerGlobalScope}} object, and its
1126+
associated <a>service worker</a>'s <a for="service worker">script resource</a>'s <a for="script
1127+
resource">has ever been evaluated flag</a> is set, then the user agent must show a message on a
1128+
developer console that the user agent will still start the <a>service worker</a> for the
1129+
<a>functional event</a> that has been stored during the very first evalution of the <a>service
1130+
worker</a> script and is asynchronously removed. [[!SERVICE-WORKERS]]
11261131

11271132
<li><p>Let <var>capture</var> be the result of <a>flattening</a> <var>options</var>.
11281133

0 commit comments

Comments
 (0)