app.js (620B)
1import { wrap, proxy } from './comlink-4.3.1.js'; 2 3report.onclick = () => { location.pathname = '/report' }; 4 5window.sandbox = new class { 6 box = wrap(new Worker('sandbox.js', { type: 'module' })); 7 run(code) { 8 return new Promise(async (resolve, reject) => { 9 const errorHandler = proxy(reject); 10 const result = await this.box.run(code, errorHandler); 11 resolve(result); 12 }); 13 } 14}(); 15 16const query = new URLSearchParams(location.search); 17const code = query.get('code') ?? '7*7'; 18let tmp = await window.sandbox.run(code); 19console.log(tmp); 20output.textContent = tmp;