Skip to content

Instantly share code, notes, and snippets.

@ravicious
Created March 13, 2026 09:29
Show Gist options
  • Select an option

  • Save ravicious/207d09c1755594dd45abe2a6b7f961ee to your computer and use it in GitHub Desktop.

Select an option

Save ravicious/207d09c1755594dd45abe2a6b7f961ee to your computer and use it in GitHub Desktop.
cross-origin isolation Chromium repo
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cross-Origin Isolation Repro</title>
<style>
body { font-family: monospace; padding: 2em; }
.pass { color: green; }
.fail { color: red; }
</style>
</head>
<body>
<h1>Cross-Origin Isolation Check</h1>
<p>crossOriginIsolated: <span id="coi"></span></p>
<p>SharedArrayBuffer: <span id="sab"></span></p>
<h2>Response Headers</h2>
<pre id="headers"></pre>
<script>
const coi = document.getElementById('coi');
coi.textContent = window.crossOriginIsolated;
coi.className = window.crossOriginIsolated ? 'pass' : 'fail';
const sab = document.getElementById('sab');
try {
new SharedArrayBuffer(1);
sab.textContent = 'available';
sab.className = 'pass';
} catch (e) {
sab.textContent = 'unavailable (' + e.message + ')';
sab.className = 'fail';
}
fetch(location.href).then(r => {
const relevant = ['cross-origin-opener-policy', 'cross-origin-embedder-policy'];
const lines = [...r.headers.entries()]
.filter(([k]) => relevant.includes(k))
.map(([k, v]) => k + ': ' + v);
document.getElementById('headers').textContent = lines.join('\n') || '(none)';
});
</script>
</body>
</html>
// Usage: node server.js
const http = require('node:http');
const fs = require('node:fs');
const path = require('node:path');
const server = http.createServer((req, res) => {
// Set cross-origin isolation headers on every response.
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
const filePath = path.join(__dirname, req.url === '/' ? 'index.html' : req.url);
const ext = path.extname(filePath);
const mimeTypes = { '.html': 'text/html', '.js': 'application/javascript', '.css': 'text/css' };
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(404);
res.end('Not found');
return;
}
res.setHeader('Content-Type', mimeTypes[ext] || 'application/octet-stream');
res.writeHead(200);
res.end(data);
});
});
server.listen(3000, () => {
console.log('http://localhost:3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment