-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
670 lines (665 loc) · 29.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
<!DOCTYPE html>
<html>
<head>
<title>
navigator.connect API
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='https://www.w3.org/Tools/respec/respec-w3c-common' class='remove'>
</script>
<script class="remove">
// (this is to make tidy happy)
// See http://www.w3.org/respec/ for ReSpec documentation.
var respecConfig = {
specStatus: "unofficial",
shortName: "navigator-connect-api",
editors: [
{
name: "Marijn Kruisselbrink",
company: "Google",
companyURL: "https://www.google.com/"
},
{
name: "Jungkee Song",
company: "Samsung Electronics",
companyURL: "http://www.samsung.com/sec/"
},
],
edDraftURI: "https://mkruisselbrink.github.io/navigator-connect/",
noLegacyStyle: true,
otherLinks: [{
key: "Participate",
data: [
{ value: "File bugs and feature requests",
href: "https://github.com/mkruisselbrink/navigator-connect/issues",
},
{ value: "Fix the text through GitHub",
href: "https://github.com/mkruisselbrink/navigator-connect",
},
],
}],
};
</script>
</head>
<body>
<section id='abstract'>
<p>
This document describes an API to facilitate cross origin communication between service
workers and webpages.
</p>
</section>
<section id='sotd'>
<p class='warning'>
This specification is not being actively maintained. It may be revived in the future,
but for now should be considered obsolete. Some of the functionality it tried to offer
can be achieved using
<a href="https://github.com/slightlyoff/ServiceWorker/issues/684">foreign fetch</a> instead.
</p>
</section>
<section class='informative' id="introduction">
<h2>
Introduction
</h2>
<p>
With the navigator.connect API clients (either webpages or some flavor of worker) can
connect to services, with these services being implemented by service workers.
</p>
<section>
<h2>
Example
</h2>
<pre class="example highlight" title="Connect to a service">
// http://example.com/webapp.js
navigator.services.connect('https://example.com/services/echo').then(
function(port) {
port.postMessage('hello');
navigator.services.addEventListener('message', function(event) {
if (event.source != port) return;
// Handle reply from the service.
});
navigator.services.addEventListener('close', function(event) {
if (event.source != port) return;
// The connection to the service was clsoed.
});
}
);
</pre>
<pre class="example highlight" title="Handle a connection request">
// https://example.com/serviceworker.js
navigator.services.addEventListener('connect', function(event) {
// Could optionally check event.origin in addition to checking targetURL to determine if that
// origin should be allowed access to this service.
if (event.targetURL === 'https://example.com/services/echo') {
event.respondWith({accept: true, name: 'echo_client'}).then(
(port) => port.postMessage('You are connected!')
);
}
});
navigator.services.addEventListener('message', function(event) {
if (event.source.name === 'echo_client') {
// Handle messages from the client.
event.source.postMessage(event.data, event.ports);
} else {
// Connections no longer of interest.
event.source.close();
}
});
</pre>
<pre class="example highlight" title="Connect to a service from a service worker">
// https://acme.com/client-sw.js
self.addEventListener('activate', function(event) {
event.waitUntil(
navigator.services.connect('https://example.com/services/analytics', {name: 'analytics'}));
});
self.addEventListener('fetch', function(event) {
navigator.services.match({name: 'analytics'}).then(
(port) => port.postMessage('log fetch'));
});
</pre>
<pre class="example highlight" title=
"Handle push event by sending a message to a stored port">
// https://example.com/serviceworker.js
self.addEventListener('push', function(event) {
event.waitUntil(navigator.services.matchAll({targetURL: 'https://example.com/services/push').then(
(ports) => ports.forEach((port) => port.postMessage('received push'))));
});
</pre>
</section>
</section>
<section>
<h2>
Terminology
</h2>
<p>
The terms <dfn><a href="http://www.w3.org/TR/html5/webappapis.html#event-handlers">event
handler</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/webappapis.html#event-handler-event-type">event handler event
type</a></dfn>, and <dfn><a href=
"http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a></dfn> are
defined in [[!HTML5]].
</p>
<p>
<code><a href=
'http://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects'><dfn>Promise</dfn></a></code>
is defined in [[!ECMASCRIPT]].
</p>
<p>
<code><a href="http://www.w3.org/TR/dom/#eventinit"><dfn>EventInit</dfn></a></code>,
<code><a href="http://www.w3.org/TR/dom/#domexception"><dfn>DOMException</dfn></a></code>,
and <code><a href="http://www.w3.org/TR/dom/#aborterror"><dfn>AbortError</dfn></a></code>
are defined in [[!DOM]].
</p>
<p>
<code><a href=
"http://www.w3.org/TR/webmessaging/#messagechannel"><dfn>MessageChannel</dfn></a></code>,
<code><a href=
"http://www.w3.org/TR/webmessaging/#messageport"><dfn>MessagePort</dfn></a></code>, and
<code><a href=
"http://www.w3.org/TR/webmessaging/#messageevent"><dfn>MessageEvent</dfn></a></code> are
defined in [[!WEBMESSAGING]]
</p>
<p>
<dfn>Service Worker</dfn>, <dfn>ServiceWorkerRegistration</dfn>, and
<dfn>ServiceWorkerGlobalScope</dfn> are defined in [[!SERVICE-WORKERS]].
</p>
</section>
<section>
<h2>
Security and privacy considerations
</h2>
<p>
Most of what is described here can already be achieved using cross origin iframes, regular
cross origin messaging, and regular service worker messaging. As such the security and
privacy implications of this API are minor. Having said that, there are a few parts that
are a few interesting security and privacy considerations to keep in mind:
</p>
<p>
User agents should not leak any information on sites a user has visited etc to other
webpages. In particular this means that a service rejecting a connection attempt should be
indistinguishable from no service being installed to service a particular URL.
</p>
<p class="note">
Currently this API only allows connecting to services that have already been installed. If
in the future some mechanism where attempting to connect to a service can trigger
installation of a service worker, this of course has its own set of security and privacy
implications.
</p>
</section>
<section>
<h2>
Model
</h2>
<p class="issue">The model definition is in flux. Especially, the concepts around a <em>service port</em> internal slot, a <em>message channel</em> between two <em>service ports</em>, and <em>entangle</em> operation need to be re-defined.</p>
<p>
A <dfn>service port</dfn> is a messageable port.
</p>
<p>
A <a>service port</a> has its <dfn>name</dfn> (a string).
</p>
<p>
A <a>service port</a> has its <dfn>data</dfn>.
</p>
<p>
A <a>service port</a> has an associated <dfn id="serviceport-connection">connection</dfn> (a <a href="#connection">connection</a>).
</p>
<p>
A <dfn id="connection">connection</dfn> is an <a href=
"https://html.spec.whatwg.org/multipage/comms.html#entangle">entangled</a> <a href=
"https://html.spec.whatwg.org/multipage/comms.html#message-channels">message channel</a>.
</p>
<p>
A <a href="#connection">connection</a> has an associated <dfn>client</dfn> (an <a href="https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object">environment settings object</a>) and an associated
<dfn>service</dfn> (an <a href="https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object">environment settings object</a> whose <a href="https://html.spec.whatwg.org/multipage/webappapis.html#global-object">global object</a> is a <a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-global-scope-interface">ServiceWorkerGlobalScope</a> object).
</p>
<p>
A <a href="#connection">connection</a> has an associated <dfn>client side port</dfn> (a <a>service port</a>)
and an associated <dfn>service side port</dfn> (a <a>service port</a>).
</p>
<p>
A <a href="#connection">connection</a> has its <dfn>target url</dfn> (a string).
</p>
<p>
A <a href=
"https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-service-worker-registration">
service worker registration</a> has an associated <a>name to service port map</a>.
</p>
<p>
An <a href="https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object">environment settings object</a> whose <a href="https://html.spec.whatwg.org/multipage/webappapis.html#global-object">global object</a> is not a <code><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-global-scope-interface">ServiceWorkerGlobalScope</a></code> object has an associated <a>name to service port map</a>.
</p>
<p>
A <a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#dfn-service-worker">service worker</a>'s <a href="https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object">environment settings object</a> does not own a <a>name to service port map</a>. A <a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#dfn-service-worker">service worker</a> uses its <a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#dfn-containing-service-worker-registration">containing service worker registration</a>'s <a>name to service port map</a>.
</p>
<p>
A <dfn>name to service port map</dfn> is a <a href=
"http://en.wikipedia.org/wiki/Multimap">Multimap</a> of the Record {[key], [value]} where
[key] is a <a>name</a> and [value] is a <a>service port</a>.
</p>
</section>
<section>
<h2>
API Description
</h2>
<section>
<h2>
<code>navigator.services</code>
</h2>
<dl title="[NoInterfaceObject] interface NavigatorServices" class="idl">
<dt>
readonly attribute ServicePortCollection services
</dt>
</dl>
<dl title="Navigator implements NavigatorServices" class="idl"></dl>
<dl title="WorkerNavigator implements NavigatorServices" class="idl"></dl>
</section>
<section>
<h2>
<a>ServicePortCollection</a> interface
</h2>
<dl title="[Exposed=(Window,Worker)] interface ServicePortCollection : EventTarget" class=
"idl" data-merge="ServicePortConnectOptions ServicePortMatchOptions">
<dt>
Promise<ServicePort> connect(DOMString url, optional ServicePortConnectOptions
options)
</dt>
<dt>
Promise<ServicePort> match(ServicePortMatchOptions options)
</dt>
<dt>
Promise<sequence<ServicePort>> matchAll(optional ServicePortMatchOptions
options)
</dt>
<dt>
[Exposed=ServiceWorker] attribute EventHandler onconnect
</dt>
<dt>
attribute EventHandler onmessage
</dt>
<dt>
attribute EventHandler onclose
</dt>
</dl>
<dl title="dictionary ServicePortConnectOptions" class="idl">
<dt>
DOMString name
</dt>
<dt>
any data
</dt>
<dt>
boolean installWorker
</dt>
</dl>
<dl title="dictionary ServicePortMatchOptions" class="idl">
<dt>
DOMString name
</dt>
<dt>
DOMString targetURL
</dt>
</dl>
<p>A <a>ServicePortCollection</a> object has an associated <dfn id="serviceportcollection-settings-object">settings object</dfn>, which is an <a href="https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object">environment settings object</a> whose <a href="https://html.spec.whatwg.org/multipage/webappapis.html#global-object">global object</a> is associated with the <a href="https://html.spec.whatwg.org/multipage/webappapis.html#navigator">Navigator</a> object or the <a href="https://html.spec.whatwg.org/multipage/workers.html#workernavigator">WorkerNavigator</a> object that the <a>ServicePortCollection</a> object is retrieved from.</p>
<p>
The <code><dfn id="widl-ServicePortCollection-onconnect">onconnect</dfn></code> attribute
is an <a>event handler</a> whose corresponding <a>event handler event type</a> is
<code><a>connect</a></code>.
</p>
<p>
The <code><dfn id="widl-ServicePortCollection-onmessage">onmessage</dfn></code> attribute
is an <a>event handler</a> whose corresponding <a>event handler event type</a> is
<code>message</code>.
</p>
<p>
The <code><dfn id="widl-ServicePortCollection-onclose">onclose</dfn></code> attribute is
an <a>event handler</a> whose corresponding <a>event handler event type</a> is
<code><a>close</a></code>.
</p>
<section>
<h2>
<code>connect(<var>url</var>, <var>options</var>)</code>
</h2>
<p>
The <code><dfn id=
"widl-ServicePortCollection-connect-Promise-ServicePort--DOMString-url-ServicePortConnectOptions-options">
connect(<var>url</var>, <var>options</var>)</dfn></code> method MUST run these steps:
</p>
<ol>
<li>If the <a href="https://dom.spec.whatwg.org/#context-object">context object</a>'s <a href="#serviceportcollection-settings-object">settings object</a>'s <a href="https://html.spec.whatwg.org/multipage/webappapis.html#global-object">global object</a> is a <code><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-global-scope-interface">ServiceWorkerGlobalScope</a></code> object and its associated <a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#dfn-service-worker-global-scope-service-worker">service worker</a> is not an <a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#dfn-active-worker">active worker</a>, return a <a href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects">promise</a> rejected with an "<code><a href="http://heycam.github.io/webidl/#invalidstateerror">InvalidStateError</a></code>" exception.</li>
<li>Let <var>url</var> be the result of parsing <var>url</var> with <a href=
"https://html.spec.whatwg.org/multipage/webappapis.html#entry-settings-object">entry
settings object</a>'s <a href=
"https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url">API base URL</a>.
</li>
<li>If <var>url</var> is failure, return a <a href=
"https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects">promise</a>
rejected with a <code>TypeError</code>.
</li>
<li>Return the result of running <a href="#connect">Connect</a> algorithm with
<var>url</var> and <var>options</var> as arguments.
</li>
</ol>
</section>
<section>
<h2>
<code>match(<var>options</var>)</code>
</h2>
<p>
The <code><dfn id=
"widl-ServicePortCollection-match-Promise-ServicePort--ServicePortMatchOptions-options">
match(<var>options</var>)</dfn></code> method MUST run these steps:
</p>
<ol>
<li>To be defined.
</li>
</ol>
</section>
<section>
<h2>
<code>matchAll(<var>options</var>)</code>
</h2>
<p>
The <code><dfn id=
"widl-ServicePortCollection-matchAll-Promise-sequence-ServicePort---ServicePortMatchOptions-options">
matchAll(<var>options</var>)</dfn></code> method MUST run these steps:
</p>
<ol>
<li>To be defined.
</li>
</ol>
</section>
</section>
<section>
<h2>
<a>ServicePort</a> interface
</h2>
<p>
An instance of the <a><code>ServicePort</code></a> interface represents a <a>service
port</a>.
</p>
<dl title="[Exposed=(Window,Worker)] interface ServicePort" class="idl">
<dt>
readonly attribute DOMString targetURL
</dt>
<dt>
readonly attribute DOMString name
</dt>
<dt>
readonly attribute any data
</dt>
<dt>
void postMessage(any message, optional sequence<Transferable> transfer)
</dt>
<dt>
void close()
</dt>
</dl>
<p>
The <code><dfn id="widl-ServicePort-targetURL">targetURL</dfn></code> attribute MUST
return the <a>service port</a>'s <a href="#serviceport-connection">connection</a>'s <a>target url</a>.
</p>
<p>
The <code><dfn id="widl-ServicePort-name">name</dfn></code> attribute MUST return the <a>service port</a>'s <a>name</a>.
</p>
<p>
The <code><dfn id="widl-ServicePort-data">data</dfn></code> attribute MUST return the <a>service port</a>' <a>data</a>.
</p>
<p>
The <code><dfn id=
"widl-ServicePort-postMessage-void-any-message-sequence-Transferable--transfer">postMessage(<var>message</var>,
<var>transfer</var>)</dfn></code> method MUST run these steps:
</p>
<ol>
<li>To be defined.
</li>
</ol>
<p>
The <code><dfn id="widl-ServicePort-close-void">close()</dfn></code> method MUST run
these steps:
</p>
<ol>
<li>To be defined.
</li>
</ol>
</section>
<section>
<h2>
The <code><dfn>connect</dfn></code> event
</h2>
<p>
The <a>ServicePortConnectEvent</a> interface represents a received connection attempt.
</p>
<dl title=
"[Constructor(DOMString type, optional ServicePortConnectEventInit eventInitDict), Exposed=ServiceWorker] interface ServicePortConnectEvent : ExtendableEvent"
class="idl" data-merge="ServicePortConnectEventInit ServicePortConnectResponse">
<dt>
readonly attribute DOMString targetURL
</dt>
<dt>
readonly attribute DOMString origin
</dt>
<dt>
Promise<ServicePort> respondWith(Promise<ServicePortConnectResponse>
response)
</dt>
</dl>
<dl title="dictionary ServicePortConnectEventInit : ExtendableEventInit" class="idl">
<dt>
DOMString targetURL
</dt>
<dt>
DOMString origin
</dt>
</dl>
<dl title="dictionary ServicePortConnectResponse" class="idl">
<dt>
boolean accept
</dt>
<dt>
DOMString name
</dt>
<dt>
any data
</dt>
</dl>
<p>
The <code><dfn id="widl-ServicePortConnectEvent-targetURL">targetURL</dfn></code>
attribute MUST return the value it was initialized to.
</p>
<p>
The <code><dfn id="widl-ServicePortConnectEvent-origin">origin</dfn></code> attribute
MUST return the value it was initialized to.
</p>
<p>
The <code><dfn id=
"widl-ServicePortConnectEvent-respondWith-Promise-ServicePort--Promise-ServicePortConnectResponse--response">
respondWith(<var>response</var>)</dfn></code> method MUST run these steps:
</p>
<ol>
<li>To be defined.
</li>
</ol>
</section>
<section>
<h2>
The <code><dfn>close</dfn></code> event
</h2>
<dl title=
"[Constructor(DOMString type, optional ServicePortCloseEventInit eventInitDict), Exposed=(Window, Worker)] interface ServicePortCloseEvent"
class="idl" data-merge="ServicePortCloseEventInit">
<dt>
readonly attribute ServicePort source
</dt>
</dl>
<dl title="dictionary ServicePortCloseEventInit : EventInit" class="idl">
<dt>
ServicePort source
</dt>
</dl>
<dl title=
"[Constructor(DOMString type, optional ExtendableServicePortCloseEventInit eventInitDict), Exposed=ServiceWorker] interface ExtendableServicePortCloseEvent : ExtendableEvent"
class="idl">
<dt>
readonly attribute ServicePort source
</dt>
</dl>
<dl title="dictionary ExtendableServicePortCloseEventInit : ExtendableEventInit" class=
"idl">
<dt>
ServicePort source
</dt>
</dl>
</section>
</section>
<section class="appendix">
<h2>
Algorithms
</h2>
<section>
<h2>
Connect
</h2>
<p class="issue">
The Connect algorithm will be re-defined.
</p>
<dl>
<dt>
Input
</dt>
<dd>
<var>url</var>, an <a href="https://url.spec.whatwg.org/#concept-absolute-url">an
absolute URL</a>
</dd>
<dd>
<var>options</var>, a <code><a>ServicePortConnectOptions</a></code> instance
</dd>
<dt>
Output
</dt>
<dd>
<var>promise</var>, a <a href=
"https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects">promise</a>
</dd>
</dl>
<ol>
<li>Let <var>promise</var> be a new <a><code>Promise</code></a>.
</li>
<li>Run the following substeps in parallel:
<ol>
<li>Let <var>registration</var> be the result of running the <a href=
"https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#scope-match-algorithm">
Match Service Worker Registration</a> algorithm on <var>url</var>
</li>
<li>If <var>registration</var> is null, and <var>options.installWorker</var> is
<code>true</code>, then:
<ol>
<li>
<p class="issue">
TODO: run <a href=
"https://github.com/mkruisselbrink/navigator-connect/blob/gh-pages/explainer.md#mommy-where-do-service-workers-come-from">
network header based installation algorithm</a>, which might change
registration to be non-null.
</p>
</li>
</ol>
</li>
<li>If <var>registration</var> is null, reject <var>promise</var> with a
<code><a>DOMException</a></code> whose name is "<code><a>AbortError</a></code>" and
terminate these steps.
</li>
<li>If <var>registration</var>'s <a href=
"https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-active-worker">
active worker</a> is not null, then:
<ol>
<li>Run the <a href=
"https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#handle-functional-event-algorithm">
Handle Functional Event</a> algorithm with <var>registration</var> and
<var>callbackSteps</var> that when invoked with <var>global</var> run the
following substeps:
<ol>
<li>Fire an event named <code><a>connect</a></code> using
<code><a>ServicePortConnectEvent</a></code> interface at
<var>global</var><code>.navigator.services</code>.
<p class="issue">
Better define these next steps.
</p>
</li>
<li>Let <var>shouldAccept</var> be the parameter passed to the first call of
<code><a>acceptConnection</a></code>, or <code>null</code> if no event
listeners called <code><a>acceptConnection</a></code>.
</li>
<li>If <var>shouldAccept</var> is <code>true</code> or a Promise resolving to
<code>true</code>, do the following:
<ol>
<li>Let <var>connection</var> be a new <a href="#connection">connection</a>.
</li>
<li>Set <var>connection</var>'s <a>name</a> to <var>url</var>.
</li>
<li>Generate a new <a href=
"http://tools.ietf.org/html/rfc4122#section-3">UUID</a> and set
<var>connection</var>'s <a>id</a> to the value.
</li>
<li>Set <var>connection</var>'s <a>client</a> to <a>connect client</a>.
</li>
<li>Set <var>connection</var>'s <a>service</a> to
<var>registration</var>'s <a href=
"https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-active-worker">
active worker</a>.
</li>
<li>
<a href=
"https://html.spec.whatwg.org/multipage/comms.html#create-a-new-messageport-object">
Create a new port</a> whose <a href=
"https://html.spec.whatwg.org/multipage/comms.html#concept-port-owner">owner</a>
is the <a>connect client</a>, and set <var>connection</var>'s <a>client
port</a> to the result value.
</li>
<li>
<a href=
"https://html.spec.whatwg.org/multipage/comms.html#create-a-new-messageport-object">
Create a new port</a> whose <a href=
"https://html.spec.whatwg.org/multipage/comms.html#concept-port-owner">owner</a>
is the <var>registration</var>'s <a href=
"https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-active-worker">
active worker</a>'s <a href=
"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object">
environment settings object</a>, and set <var>connection</var>'s
<a>service port</a> to the result value.
</li>
<li>
<a href=
"https://html.spec.whatwg.org/multipage/comms.html#entangle">Entangle</a>
the <a>client port</a> and the <a>service port</a>.
</li>
<li>Set a newly-created <a href=
"http://people.mozilla.org/~jorendorff/es6-draft.html#sec-list-and-record-specification-type">
Record</a> {[key]: <var>connection</var>'s <a>name</a>, [value]:
<var>connection</var>} to <a>name to connection map</a>.
</li>
</ol>
</li>
<li>Else, reject <var>promise</var> with a <code><a>DOMException</a></code>
whose name is "<code><a>AbortError</a></code>".
</li>
</ol>
</li>
</ol>
</li>
<li>Else:
<p class="issue">
Figure out sensible behavior when there is no active worker. Probably wait for
some worker to become the active worker?
</p>
</li>
</ol>
</li>
<li>Return <var>promise</var>.
</li>
</ol>
<p class="issue">
Somehow phrase this to allow other ways for a user agent to connect to services, in
particular services that are not implemented as a service worker.
</p>
</section>
</section>
</body>
</html>