New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

iframe-shield

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iframe-shield

Prevent iframe memory crashes on iOS Safari. Smart memory management, quality scaling, and lifecycle control for heavy WebGL/game iframes.

Source
npmnpm
Version
1.3.6
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

npm version downloads bundle size license zero deps

iframe-shield

Your iframes are crashing your users' phones. This fixes that.

Smart memory management for heavy WebGL and game iframes.
Zero dependencies. TypeScript. Any framework.

The problem

A WebGL game iframe uses 600 MB+. iOS Safari gives your tab ~650 MB total. Your user opens a payment modal, switches tabs, or receives a notification — the browser kills the page instantly. No error. No callback. Just a white screen.

This happens to every game platform, every day, on every iPhone.

Before & After

Without iframe-shieldWith iframe-shield
iPhone 12 — game + paymentTab killed. White screen. User loses game progress.Game memory managed. Payment opens safely. Zero crashes.
iPhone 15 — user switches to MessagesBackground tab killed within 3 seconds.Auto-freeze on background. Resume on return. No reload.
iPad — 2 game iframes on same pageSecond iframe load crashes the entire tab.Only 1 active at a time. Others frozen with placeholders.
Android low-end — 600MB gameJanky. 5fps. Eventually OOM.Auto-detects device. Reduces load to match capability.
Desktop Chrome — same codeWorks fine (no intervention needed).Detects desktop. Steps back. Zero overhead.

Install

npm install iframe-shield

3 lines. That's it.

import { IframeShield } from 'iframe-shield';

const shield = new IframeShield();
shield.register('#game-iframe', { estimatedMemoryMB: 700 });

Everything else is automatic. Device detection. Quality scaling. Background freeze. Crash recovery.

React

import { useIframeShield } from 'iframe-shield/react';

function Game({ url }) {
  const { iframeRef } = useIframeShield({
    src: url,
    estimatedMemoryMB: 700,
    config: { quality: 'auto', crashRecovery: { enabled: true } },
  });

  return <iframe ref={iframeRef} src={url} />;
}

What it does

Device Profiling

Detects the device and applies the right strategy. You don't configure anything.

DeviceBudgetStrategy
iPhone SE / older Android600 MBAggressive — low quality, tight watermarks
iPhone 12-15800 MBBalanced — auto quality, normal watermarks
iPhone 16 Pro / flagship Android1000 MBRelaxed — higher quality, wider margins
iPad1000 MBRelaxed
Laptop / Desktop1500 MBHands off — monitoring only
Gaming PC2500 MBMonitoring only

Memory Zones

Five zones. Each one triggers a proportional response.

[==========Green==========][===Yellow===][==Red==][Critical][!]
0%                        60%           75%      85%       95%
ZoneWhat happens
GreenNothing. Everything is fine.
YellowQuality steps down one level.
RedNon-visible iframes frozen. Quality at minimum.
CriticalOnly 1 iframe survives. Everything else frozen.
EmergencyLow-priority iframes destroyed. System cleanup.

Quality Control

shield.setQuality(id, 'high');    // Full resolution
shield.setQuality(id, 'medium');  // Balanced
shield.setQuality(id, 'low');     // Performance
shield.setQuality(id, 'minimal'); // Survival

// Or don't think about it
new IframeShield({ quality: 'auto' });

Manual changes are respected for 30 seconds before auto-pilot takes over again.

Game Proxy

Load third-party games through a same-origin proxy. Full control over resource allocation.

import { GameProxy } from 'iframe-shield';

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

await proxy.createProxyIframe('https://game-server.com/game', container);

Real-time allocation reporting via postMessage.

iOS Safari Shield

Built specifically for Safari's jetsam process killer.

SignalResponse
User switches tabsAll iframes frozen instantly
App goes to backgroundLow-priority iframes destroyed
Memory pressure detectedProgressive quality reduction
Tab was previously killedRestart at lower quality
System nearing limitBlock new iframe loads

Crash Recovery

Browser killed your tab? We detect it on the next visit and restart at lower quality.

new IframeShield({
  crashRecovery: { enabled: true, maxRecoveryAttempts: 3 },
  onCrashRecovered: (info) => {
    console.log(`Crash #${info.recoveryAttempt} — loading at ${info.restoredQuality}`);
  },
});

Three crashes in a row? We go to minimal quality and stay there until stable for 30 seconds.

Graduated Freeze

shield.freeze(id, 1); // Light — state preserved
shield.freeze(id, 2); // Medium — rendering suspended
shield.freeze(id, 3); // Full — memory released, reload needed

shield.resume(id);     // Works from any level

Debug Overlay

Shadow DOM visual debugger. No framework dependency.

new IframeShield({
  debugger: { enabled: true, position: 'bottom-right', shortcut: 'ctrl+shift+q' },
});

Quality buttons. Memory bar. Event timeline. All in an isolated Shadow DOM that won't touch your styles.

Network Budget

new IframeShield({
  networkBudget: { enabled: true, maxTransferMB: 500 },
});

Tracks bytes per domain. Acts when budgets are exceeded.

Memory Logger

const events = shield.exportMemoryLog();

500-entry circular buffer. Every zone change, quality shift, freeze, and crash — timestamped and exportable.

API

MethodWhat it does
new IframeShield(config?)Create instance. Auto-detects device.
.register(target, opts?)Protect an iframe. Returns ID.
.setQuality(id, level)'high' / 'medium' / 'low' / 'minimal'
.freeze(id, level?)Freeze at level 1-3
.resume(id)Resume from any freeze
.destroy(id)Remove and free all memory
.getStats()Memory zone, per-iframe stats
.getMemoryZone()Current zone: green → emergency
.dispose()Cleanup everything

Browser Support

BrowserSupport
iOS Safari 14+Full (primary target)
Chrome / Edge 80+Full
Firefox 75+Full
Safari macOS 14+Full
Android ChromeFull

Comparison

Featureiframe-shieldNo protectionManual setTimeout
Automatic device detectionYesNoNo
Memory pressure response5 zonesNoneSingle threshold
iOS Safari jetsam preventionYesNoPartial
Crash recoveryAutoManual reloadManual reload
Quality degradation4 levelsNoneOn/Off
Background tab handlingAuto freezeNoneManual
Debug toolsBuilt-in overlayDevTools onlyConsole.log
Third-party iframe supportGame ProxyNoneNone
React hookYesN/AN/A
Dependencies0N/AN/A
Bundle size~25 KB gzipped0~0.5 KB

License

Apache 2.0 — see LICENSE.

npm · GitHub · Landing Page

Keywords

iframe

FAQs

Package last updated on 16 Mar 2026

Related posts