Knowledgebase

Extension Architecture and Service Workers Print

  • googletechnology, google, woocommerce, guide, howto, solution, zillionkinghost, hosting
  • 0

How the parts communicate.

WHAT THE SERVICE WORKER DOES

Handles events, coordinates, and communicates with servers.

WHAT IS DIFFERENT ABOUT IT

It terminates when idle, and restarts on the next event.

WHAT THAT MEANS

Anything held in a variable is lost.

WHAT TO DO ABOUT IT

Persist state in storage, and read it when needed.

WHAT CONTENT SCRIPTS DO

Run within a page, able to read and modify it.

WHAT THEY CANNOT DO

Access most extension capabilities directly.

HOW THEY COMMUNICATE

By sending messages to the service worker.

WHAT TO DESIGN

A clear message protocol between components.

WHAT TO BE CAREFUL WITH

Content scripts conflicting with the page's own scripts Assuming a page's structure, which changes Injecting into pages where you were not intended

WHAT ISOLATION MEANS

Content scripts share the page's document but not its script environment.

WHY THAT MATTERS

You cannot directly call the page's own functions, and vice versa.

WHAT TO USE FOR STORAGE

The extension storage, which synchronises or stays local.

WHAT TO NEVER STORE THERE

Secrets, which are readable.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot