1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19

content / test / data / service_worker / hello.js [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

self.addEventListener('fetch', (event) => {
  // Responds to requests containing "hello_sw".
  if (event.request.url.includes('hello_sw')) {
    event.respondWith(
      fetch('hello-from-sw.txt').then((response) => {
        return response;
      }));
  }
});

self.addEventListener('message', (event) => {
  if (event.data == 'postMessage from the page') {
    event.source.postMessage('postMessage from the service worker');
  }
});