Scramjet provides factory functions that load the appropriate APIs for different contexts. These functions are available globally after loading the Scramjet bundle.
$scramjetLoadController()
Factory function that creates the ScramjetController class for the window context.
function $scramjetLoadController(): { ScramjetController: typeof ScramjetController }
Returns
An object containing the ScramjetController class.
Example
const { ScramjetController } = $scramjetLoadController();
const scramjet = new ScramjetController({
prefix: "/scramjet/"
});
await scramjet.init();
const frame = scramjet.createFrame();
document.body.appendChild(frame.frame);
frame.go("https://example.com");
$scramjetLoadClient()
Factory function that creates the ScramjetClient class for controlling sandboxing.
function $scramjetLoadClient(): { ScramjetClient: typeof ScramjetClient }
Returns
An object containing the ScramjetClient class.
Example
const { ScramjetClient } = $scramjetLoadClient();
const scramjetClient = new ScramjetClient(window);
Most users won’t need to interact with ScramjetClient directly. It’s automatically created when using ScramjetController and ScramjetFrame.
$scramjetLoadWorker()
Factory function that creates the ScramjetServiceWorker class for the service worker context.
function $scramjetLoadWorker(): { ScramjetServiceWorker: typeof ScramjetServiceWorker }
Returns
An object containing the ScramjetServiceWorker class.
Example - Plain service worker
// In your service worker
const { ScramjetServiceWorker } = $scramjetLoadWorker();
const scramjet = new ScramjetServiceWorker();
self.addEventListener("fetch", async (ev) => {
await scramjet.loadConfig();
if (scramjet.route(ev)) {
ev.respondWith(scramjet.fetch(ev));
}
});
Example - Workbox routing
// In your service worker (ensure you are using a bundler for Workbox)
// This is more useful for a webOS or if you have offline PWA support on your proxy site
import { registerRoute } from 'workbox-routing';
const { ScramjetServiceWorker } = $scramjetLoadWorker();
const scramjet = new ScramjetServiceWorker();
registerRoute(
({ request }) => {
return scramjet.route({ request });
},
async ({ event }) => {
await scramjet.loadConfig();
return scramjet.fetch(event);
}
);
$scramjetVersion
Version information for the current Scramjet build.
const $scramjetVersion: ScramjetVersionInfo
Type
interface ScramjetVersionInfo {
/** The git commit hash that this build was created from */
build: string;
/** The semantic version */
version: string;
}
Example
console.log(`Scramjet v${$scramjetVersion.version}`);
console.log(`Build: ${$scramjetVersion.build}`);