Prerequisites
Before you begin, ensure you have:- A web server capable of serving static files
- Service worker support in your target browsers
- The Scramjet distribution files (
scramjet.all.js,scramjet.wasm.wasm,scramjet.sync.js)
Installation
Include Scramjet files
Place the Scramjet distribution files in your project directory. These files should be accessible via your web server:
Register the service worker
Create a script to register Scramjet’s service worker. This is essential for intercepting and proxying requests:
The service worker file (
sw.js) should import Scramjet using importScripts('/scramjet.all.js') and set up the fetch handler. See the quickstart guide for a complete service worker example.The
scope parameter defines the URL prefix that the service worker will intercept. By default, Scramjet uses /scramjet/.Initialize the controller
After the service worker is registered and ready, load and initialize the Scramjet controller:
Complete example
Here’s a full working example that ties everything together:Configuration options
TheScramjetController constructor accepts a configuration object with the following options:
prefix
prefix
The URL prefix for the proxy. Defaults to
/scramjet/.flags
flags
Feature flags that control Scramjet’s behavior. See Configuration flags for details.
codec
codec
Custom URL encoding/decoding functions. See Custom codecs for details.
files
files
Paths to Scramjet distribution files.
Next steps
Working with frames
Learn how to create and manage isolated browsing contexts
Event handling
Handle navigation and download events
Configuration flags
Customize Scramjet’s behavior with feature flags
Custom codecs
Implement custom URL encoding strategies