@@ -6,81 +6,18 @@ onactivate = () => {
6
6
return clients . claim ( ) ;
7
7
} ;
8
8
9
- onmessage = ( messageEvent ) => {
10
- registration
11
- . showNotification ( `ServiceWorkerGlobalScope Title ${ messageEvent . data } ` , {
12
- body : `ServiceWorkerGlobalScope Body ${ messageEvent . data } ` ,
13
- icon : "../resources/happy.jpg" ,
14
- } )
15
- . then ( ( ) => {
16
- messageEvent . source . postMessage (
17
- "ServiceWorkerGlobalScope showNotification() succeeded."
18
- ) ;
19
- } )
20
- . catch ( ( error ) => {
21
- messageEvent . source . postMessage (
22
- `ServiceWorkerGlobalScope showNotification() failed: ${ error } .`
23
- ) ;
24
- } ) ;
9
+ onfetch = ( fetchEvent ) => {
10
+ console . log ( fetchEvent . request . url ) ;
11
+ fetchEvent . respondWith ( fetch ( fetchEvent . request ) ) ;
25
12
} ;
26
13
27
14
onnotificationclick = ( event ) => {
28
- const notification = event . notification ;
29
-
30
- clients . matchAll ( ) . then ( ( resultList ) => {
31
- resultList . forEach ( ( client ) => {
32
- client . postMessage (
33
- `ServiceWorkerGlobalScope 'click' event for: ${
34
- notification . title
35
- } , timestamp: ${ new Date (
36
- notification . timestamp
37
- ) } , requireInteraction: ${ notification . requireInteraction } , silent: ${
38
- notification . silent
39
- } `
40
- ) ;
41
- notification . close ( ) ;
42
- } ) ;
43
- } ) ;
44
-
45
- if ( event . action === "open_window" ) {
46
- event . waitUntil (
47
- new Promise ( ( resolve ) => {
48
- setTimeout ( ( ) => {
49
- clients . openWindow ( "on-click.html" ) ;
50
- resolve ( ) ;
51
- } , 0 ) ;
52
- } )
53
- ) ;
54
- } else {
55
- // Focus existing client.
56
- event . waitUntil (
57
- clients . matchAll ( ) . then ( ( resultList ) => {
58
- if ( resultList . length > 0 ) {
59
- return resultList [ 0 ] . focus ( ) ;
60
- }
61
- } )
62
- ) ;
63
- }
64
- } ;
65
-
66
- onnotificationclose = ( event ) => {
67
15
clients . matchAll ( ) . then ( ( resultList ) => {
68
16
resultList . forEach ( ( client ) => {
69
17
const notification = event . notification ;
70
18
client . postMessage (
71
- `ServiceWorkerGlobalScope 'close' event for: ${
72
- notification . title
73
- } , timestamp: ${ new Date (
74
- notification . timestamp
75
- ) } , requireInteraction: ${ notification . requireInteraction } , silent: ${
76
- notification . silent
77
- } `
19
+ `Service-worker: Action '${ event . action } ' for: ${ notification . title } `
78
20
) ;
79
21
} ) ;
80
22
} ) ;
81
23
} ;
82
-
83
- onfetch = ( fetchEvent ) => {
84
- console . log ( fetchEvent . request . url ) ;
85
- fetchEvent . respondWith ( fetch ( fetchEvent . request ) ) ;
86
- } ;
0 commit comments