Skip to content

Commit 2b9ac55

Browse files
feat: Inline WebView bundle (#2528)
Inline the Snaps execution bundle in the WebView index.html, this will get us closer to running Snaps without a remote execution environment on mobile.
1 parent 3fb0882 commit 2b9ac55

File tree

1 file changed

+24
-6
lines changed
  • packages/snaps-execution-environments/scripts

1 file changed

+24
-6
lines changed

packages/snaps-execution-environments/scripts/build.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const ENTRY_POINTS = {
3434
webview: {
3535
entryPoint: './src/webview/index.ts',
3636
html: true,
37+
inlineBundle: true,
3738
},
3839
};
3940

@@ -99,18 +100,30 @@ async function main() {
99100
<html>
100101
<head>
101102
<meta charset="utf-8" />
102-
<title>MetaMask Snaps Iframe Execution Environment</title>
103+
<title>MetaMask Snaps Execution Environment</title>
103104
<script>${lavaMoatRuntimeBrowser}</script>
104105
</head>
105106
<body>
106107
<script src="bundle.js"></script>
107108
</body>
108109
</html>`;
109110

111+
const createInlinedHTML = (bundleSource) => `<!DOCTYPE html>
112+
<html>
113+
<head>
114+
<meta charset="utf-8" />
115+
<title>MetaMask Snaps Execution Environment</title>
116+
<script>${lavaMoatRuntimeBrowser}</script>
117+
</head>
118+
<body>
119+
<script>${bundleSource}</script>
120+
</body>
121+
</html>`;
122+
110123
await Promise.all(
111124
Object.entries(ENTRY_POINTS).map(async ([key, config]) => {
112125
console.log('Bundling', key);
113-
const { html, node, worker, entryPoint } = config;
126+
const { html, node, worker, entryPoint, inlineBundle } = config;
114127
const insertGlobalVars = node
115128
? { process: undefined, ...LavaMoatBrowserify.args.insertGlobalVars }
116129
: LavaMoatBrowserify.args.insertGlobalVars;
@@ -218,14 +231,19 @@ async function main() {
218231
outputBundle = `${runtime}\n${outputBundle}`;
219232
}
220233

221-
const bundlePath = path.join(OUTPUT_PATH, key, OUTPUT_BUNDLE);
222-
await fs.mkdir(path.dirname(bundlePath), { recursive: true });
223-
await fs.writeFile(bundlePath, outputBundle);
234+
if (!inlineBundle) {
235+
const bundlePath = path.join(OUTPUT_PATH, key, OUTPUT_BUNDLE);
236+
await fs.mkdir(path.dirname(bundlePath), { recursive: true });
237+
await fs.writeFile(bundlePath, outputBundle);
238+
}
224239

225240
if (html) {
226241
const htmlPath = path.join(OUTPUT_PATH, key, OUTPUT_HTML);
227242
await fs.mkdir(path.dirname(htmlPath), { recursive: true });
228-
await fs.writeFile(htmlPath, htmlFile);
243+
await fs.writeFile(
244+
htmlPath,
245+
inlineBundle ? createInlinedHTML(outputBundle) : htmlFile,
246+
);
229247
}
230248

231249
const outputBytes = stringToBytes(outputBundle);

0 commit comments

Comments
 (0)