Quickstart
This guide will walk you through setting up a basic Scramjet proxy. You’ll learn how to register a service worker, initialize the controller, and create a proxied iframe.Setup overview
A Scramjet proxy requires two main components:- Service worker - Intercepts and rewrites network requests
- Controller - Manages frames and communicates with the service worker
1
Create the service worker
Create a file called
sw.js in your static directory:sw.js
This service worker intercepts all fetch requests. If a request matches Scramjet’s routing (based on the configured prefix), it’s proxied. Otherwise, it’s passed through normally.
2
Set up your HTML page
Create an HTML page that will load Scramjet and register the service worker:
index.html
3
Initialize Scramjet controller
Create
app.js to register the service worker and set up the controller:app.js
4
Serve the static files
Make sure the Scramjet static files are available at the configured paths:
/scramjet/scramjet.bundle.js/scramjet/scramjet.all.js/scramjet/scramjet.wasm.wasm
dist directory of the @mercuryworkshop/scramjet package.5
Test your setup
Start your web server and open the page in a browser. You should see example.com loaded in the iframe through the Scramjet proxy.
Configuration options
TheScramjetController accepts several configuration options:
Basic options
Feature flags
Control Scramjet’s behavior with flags:Working with frames
Scramjet provides aScramjetFrame class for managing proxied iframes:
URL encoding and decoding
You can encode and decode URLs using the controller:Using Workbox (optional)
For more advanced service worker routing, you can use Workbox:sw.js
Next steps
Now that you have a working Scramjet setup, you can:- Customize the codec to implement custom URL encoding schemes
- Add event listeners to handle navigation and downloads
- Configure site-specific flags for better compatibility
- Explore the TypeScript API documentation for advanced features
Common issues
Service workers require HTTPS in production environments (except for localhost). Make sure your site is served over HTTPS.