aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/serviceworkerregistration/active/index.html
blob: 5d657279d921634afc5354a6cc23ea732778b930 (plain)
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
---
title: ServiceWorkerRegistration.active
slug: Web/API/ServiceWorkerRegistration/active
translation_of: Web/API/ServiceWorkerRegistration/active
---
<div>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</div>

<p>The <strong><code>active</code></strong> property of the {{domxref("ServiceWorkerRegistration")}} interface returns a service worker whose {{domxref("ServiceWorker.state")}} is <code style="font-style: normal;">activating</code> or <code style="font-style: normal;">activated</code>. This property is initially set to <code style="font-style: normal;">null</code>.</p>

<p>An active worker controls a {{domxref("ServiceWorkerClient")}} if the client's URL falls within the scope of the registration (the <code>scope</code> option set when {{domxref("ServiceWorkerContainer.register")}} is first called.)</p>

<div class="note">
<p><strong>Note</strong>: This feature is available in <a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers</a>.</p>
</div>

<h2 id="Syntax" name="Syntax" style="line-height: 30px; font-size: 2.14285714285714rem;">Syntax</h2>

<pre class="syntaxbox" style="font-size: 14px;">sw = ServiceWorker.active
</pre>

<h3 id="Value">Value</h3>

<p>A {{domxref("ServiceWorker")}} object, if it is currently in an <code>activating</code> or <code>activated</code> state.</p>

<h2 id="Specifications" style="line-height: 30px; font-size: 2.14285714285714rem;">Specifications</h2>

<div> </div>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col"><font face="Open Sans, sans-serif"><span style="font-weight: normal;">Specification</span></font></th>
   <th scope="col"><font face="Open Sans, sans-serif"><span style="font-weight: normal;">Status</span></font></th>
   <th scope="col"><font face="Open Sans, sans-serif"><span style="font-weight: normal;">Comment</span></font></th>
  </tr>
  <tr>
   <td>{{SpecName('Service Workers', '#service-worker-registration-active-attribute', 'ServiceWorkerRegistration.active')}}</td>
   <td>{{Spec2('Service Workers')}}</td>
   <td>Initial definition.<br>
     </td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

{{Compat("api.ServiceWorkerRegistration.active")}}

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Using Service Workers</a></li>
 <li><a href="https://github.com/mdn/sw-test">Service workers basic code example</a></li>
 <li><a href="https://jakearchibald.github.io/isserviceworkerready/">Is ServiceWorker ready?</a></li>
 <li>{{jsxref("Promise")}}</li>
 <li><a href="/en-US/docs/Web/Guide/Performance/Using_web_workers">Using web workers</a></li>
</ul>