Skip to main content

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:
  1. Service worker - Intercepts and rewrites network requests
  2. 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
The prefix option determines which URL paths are handled by Scramjet. In this example, any request to /scramjet/* will be proxied.
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
These files are in the 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

The ScramjetController accepts several configuration options:

Basic options

Feature flags

Control Scramjet’s behavior with flags:
Some flags like syncxhr and serviceworkers enable experimental features that may impact performance or compatibility.

Working with frames

Scramjet provides a ScramjetFrame 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
Workbox routing is useful if you’re building a PWA with offline support alongside your proxy functionality.

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

If CAPTCHAs aren’t working, make sure you’re not hosting on a datacenter IP. Residential IPs work best for CAPTCHA-heavy sites like Google and YouTube.
Service workers require HTTPS in production environments (except for localhost). Make sure your site is served over HTTPS.