If you were asked to implement API logging for an existing application, what will your approach be? The most common approaches are to either change the client-side code or the server-side code, or both.
By using a service worker, we can intercept client requests and gather information, and then send them to a log API.
To get started with service workers, you will need to have the service worker experiment feature turned on in your browser settings. If you have not done this yet, refer to the first recipe of Chapter 1, Learning Service Worker Basics: Setting up service workers. Service workers only run across HTTPS. To find out how to set up a development environment to support this feature, refer to the following recipes: Setting up GitHub pages for SSL, Setting up SSL for Windows, and Setting up SSL for Mac.
Follow these instructions to set up your file structure:
Download all the files from the following location: