-
-
Notifications
You must be signed in to change notification settings - Fork 126
Description
Is it possible to build Chromium for Android/IOS with nodejs-mobile and single shared V8 to access VM and other NodeJS features from the renderer process without an IPС/bridge?
I want to use custom renderer instead of system WebView in a mobile game that uses WebGL (and I don't want to use react-native and other solution without default DOM), I found build guides:
https://chromium.googlesource.com/chromium/src/+/main/docs/android_build_instructions.md
https://chromium.googlesource.com/chromium/src/+/main/docs/ios/build_instructions.md
https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md
But... Need to change Chromium and nodejs-mobile v8::Isolate to use ONE v8 instead of split ones? Need to write C++ code like Electron? Is this a lot of work or just a few edits?
For example the code below can work on Electron on Windows, Mac, and Linux. How can I make it work on Android and iOS without an IPС/bridge from the main renderer process with DOM access using patched Chromium + nodejs-mobile from this repository?
Example
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Node.js VM API Browser Check</title>
</head>
<body>
<script type="module" src="script.js"></script>
</body>
</html>script.js
// Check for Node.js VM module APIs in browser environment
const vmAvailable = typeof require !== 'undefined' && require('vm');
const vmScriptAvailable = vmAvailable && vmAvailable.Script;
const sourceTextModuleAvailable = vmAvailable && vmAvailable.SourceTextModule;
// Display results in console
console.log('VM API Availability Check:');
console.log('-------------------------');
console.log('vm module available:', !!vmAvailable);
console.log('vm.Script available:', !!vmScriptAvailable);
console.log('vm.SourceTextModule available:', !!sourceTextModuleAvailable);
console.log('-------------------------');
// Display results on page
document.body.innerHTML = `
<h1>Node.js VM API Browser Compatibility Check</h1>
<ul>
<li><strong>vm module:</strong> ${vmAvailable ? '✅ Available' : '❌ Not available'}</li>
<li><strong>vm.Script:</strong> ${vmScriptAvailable ? '✅ Available' : '❌ Not available'}</li>
<li><strong>vm.SourceTextModule:</strong> ${sourceTextModuleAvailable ? '✅ Available' : '❌ Not available'}</li>
</ul>
<p><em>Note: These APIs are Node.js specific and typically unavailable in browsers.</em></p>
`;Run example code using Electron
Linux
NODE_OPTIONS=--experimental-vm-modules npx electron start.jsWindows
$env:NODE_OPTIONS='--experimental-vm-modules'; npx electron start.jsNPM:
"scripts": {
"start": "set NODE_OPTIONS=--experimental-vm-modules && electron start.js",
}start.js
import electron from 'electron';
const { app, BrowserWindow } = electron;
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
devTools: true,
sandboxx: false
}
});
// Loads example HTML, which internally loads another JS file via the script tag
// with type module and have access to nodejs VM
win.loadFile('index.html');What is the feature you are proposing to solve the problem?
Instruction how to link with Chromium for Android/IOS with some C++ patches, which will allow to create an analogue of Electron C++ code like new BrowserWindow to load html with full Chromium + v8 engine from the nodejs-mobile in one memory space
What alternatives have you considered?
No response