/**
* Game Processor
*
* Fetches and processes archive.org game HTML for embedding in MCP Apps.
* Uses for relative URL resolution,
* and rewrites ES module import() calls to classic
`,
);
}
// Convert inline ES module scripts to classic scripts
html = convertModuleScripts(html);
// Fetch the emulation script server-side and serve from local endpoint
html = await rewriteEmulationScript(html, serverPort);
return html;
}
/**
* Fetches emulation.min.js server-side, rewrites import() → loadScript(),
* caches it, and points the HTML `);
} catch {
// If fetch fails, leave the original script tag
}
return html;
}
/**
* Converts ES module scripts to classic scripts and rewrites inline
* import() calls to use window.loadScript().
*/
function convertModuleScripts(html: string): string {
return html.replace(
/(