Building Browser Extensions by 2023

Building Browser Extensions by 2023

Author:2023
Language: eng
Format: epub


CHapTer 7 BaCkGround SCrIpTS

This simple extension service worker sets listeners for the runtime.

onInstalled, bookmark.onCreated, and webNavigation.onCompleted

events. Each handler prints a log statement to the console when those

events are fired.

Similarities

The W3C specification for service workers begins with the following high-

level characterization:

The core of this specification is a worker that wakes to

receive events.

In this respect, a web page service worker and an extension service

worker are serving the same purpose. What’s more, the distinction

between a “web page” service worker and an “extension” service worker

only describes how the service worker is deployed in that context; the

underlying service worker platform remains unchanged.

When comparing the two examples from above, you may have noticed

the following:

• Both service worker scripts are largely composed

of event handlers being assigned in the top level of

the script.

• Both service workers are listening for some form of an

installation event.

• Both service workers can access network requests

occurring in the browser.

These similarities underscore many of the similarities between the

two. With these code similarities in mind, let’s explore the ways that these

service worker contexts are alike.

190



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.