• Stars
    star
    369
  • Rank 115,223 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross-origin isolation (COOP and COEP) through a service worker for situations in which you can't control the headers (e.g. GH pages)

coi-serviceworker

npm size

Cross-origin isolation (COOP and COEP) through a service worker for situations in which you can't control the headers (e.g. GH pages).

Usage

  1. Download coi-serviceworker.js (or coi-serviceworker.min.js).
  2. Put it next to your index file (or in any folder above it)
  3. Add to your HTML file:
    <script src="coi-serviceworker.js"></script>

This script will reload the page on the user's first load to magically add the required COOP and COEP headers in a service worker.

Rules:

  • It must be in a separate file, you can't bundle it along with your app.
  • It can't be loaded from a CDN: it must be served from your own origin.
  • Your page will still need to be either served from HTTPS, or served from localhost.

Extra credits: download from NPM

You can install this package from npm:

npm i --save coi-serviceworker

You will still have to tell your bundler to put the file alongside your bundle. Something like this will do the trick:

cp node_modules/coi-serviceworker/coi-serviceworker.js dist/

Customization

You can customize the behavior by defining a variable coi in the global scope (i.e. on the window object):

window.coi = {
    // // A function that is run to decide whether to register the SW or not.
    // You could for instance make this return a value based on whether you actually need to be cross origin isolated or not.
    shouldRegister: () => true,
    // If this function returns true, any existing service worker will be deregistered (and nothing else will happen).
    shouldDeregister: () => false,
    // A function that is run to decide whether to use "Cross-Origin-Embedder-Policy: credentialless" or not.
    // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy#browser_compatibility
    coepCredentialless: () => !(navigator.userAgent.indexOf("CriOS") > -1 || !window.chrome),
    // Override this if you want to prompt the user and do reload at your own leisure. Maybe show the user a message saying:
    // "Click OK to refresh the page to enable <...>"
    doReload: () => window.location.reload(),
    // Set to true if you don't want coi to log anything to the console.
    quiet: false
}

Library and idea based on @stefnotch's blog post.

License

MIT

Carp or Koi Artwork

Carp or Koi (1926) by Ohara Koson. Original from the Los Angeles County Museum of Art. Public Domain CC0 image.

More Repositories

1

starboard-notebook

In-browser literate notebooks
TypeScript
1,217
star
2

tygo

Generate Typescript types from Golang source code
Go
592
star
3

nn-transfer

Convert trained PyTorch models to Keras, and the other way around
Python
226
star
4

luna16

LUNA16 Lung Nodule Analysis - NWI-IMC037 Final Project
Python
183
star
5

zarr.js

Javascript implementation of Zarr
TypeScript
132
star
6

GConsole

Developer Console for Unity3D
C#
101
star
7

starboard-cli

Starboard CLI for local (offline) editing of notebooks
CSS
20
star
8

LD49

TypeScript
20
star
9

starboard-observable

Observable cells in Starboard Notebook. Why not?
TypeScript
20
star
10

jpeg-artifact-reduction

Jupyter Notebook
16
star
11

starboard-jupyter

Plugin to run Starboard cells in an external Jupyter kernel
TypeScript
15
star
12

starboard-wrap

🌯A small library that wraps a Starboard Notebook iframe in the parent webpage
TypeScript
14
star
13

wasmwrap

Wrap WASM into JS files as base64
TypeScript
13
star
14

hx-ash

Entity Component Framework
Haxe
12
star
15

jupystar

Convert Jupyter notebooks (ipynb) to Starboard notebooks
Jupyter Notebook
8
star
16

starboard-python

Plugin that adds Python cells to Starboard
8
star
17

no-free-plan

HTML
8
star
18

rollup-plugin-base64

A rollup plugin that allows you to import files as a base64 string
JavaScript
7
star
19

flipper

🐬 Flipper is a monitoring service that automatically re-points floating IPs at healhy targets.
Go
7
star
20

li-hackathon

48 hour hackathon project: From RU with Love
Vue
6
star
21

nasync-js

What if JS didn't have await and async, because everything is async and awaited?
TypeScript
5
star
22

starlit

Go
4
star
23

WebMetaverse

Supposedly the 3D world wide web.
JavaScript
3
star
24

whole-slide-breast-cancer-classification

Resulting publication http://spie.org/Publications/Journal/10.1117/1.JMI.4.4.044504
Jupyter Notebook
3
star
25

HRI

Human Robot Interaction course project (robot cooking assistant with NLP)
Python
3
star
26

starcloud

CDN origin for Starboard assets with the correct headers set
Go
2
star
27

advent-of-code-2020

Advent of Code 2020 Solutions
2
star
28

LD30

"Connected Worlds"
C#
2
star
29

GConsoleNGUI

NGUI Frontend for GConsole
C#
2
star
30

ai-at-the-web-scale

Final project for "AI at the web scale" course (profit optimization for webshop -> contextual bandit problem)
Python
1
star
31

magiclogin-docs

Docs for https://magiclogin.net
1
star
32

excess

Performant WebRTC signalling server (written in Elixir)
Elixir
1
star
33

gamejam

GAMEJAM games
ASP
1
star
34

Mash

Mash, 2D Game Engine with Ash Entity System Framework
Haxe
1
star