Game Proxy

Load third-party games through a same-origin proxy to gain full control over resource usage and memory allocation.

How It Works

  1. Fetches game HTML via fetch() (requires CORS)
  2. Rewrites relative URLs to absolute
  3. Injects WebGL interceptor before game scripts
  4. Serves as blob: iframe (same-origin)

Usage

import { GameProxy } from 'iframe-shield';

const proxy = new GameProxy({
  interceptor: {
    maxTextureSize: 1024,
    maxCanvasWidth: 1280,
    maxCanvasHeight: 720,
    maxDevicePixelRatio: 1,
    maxFps: 30,
    maxWasmMemoryMB: 256,
    audioSampleRate: 22050,
  },
});

await proxy.createProxyIframe('https://game-server.com/game', container, (report) => {
  console.log('GPU allocated:', report.totalAllocatedMB, 'MB');
});

Interceptor Report

The proxy sends allocation reports every 5 seconds via postMessage:

{
  totalAllocatedMB: 185,
  breakdown: { texturesMB: 80, compressedMB: 45, renderbuffersMB: 10, wasmMB: 50 },
  stats: { textureCount: 24, downscaledCount: 18, fetchRequests: 156 },
  config: { maxTextureSize: 1024, maxFps: 30, dpr: 1 }
}
Tip: The game server must have Access-Control-Allow-Origin: * or your origin for the proxy to work without a CORS backend.