[browser][coreclr] Fix corerun to run in browser again#125322
Merged
radekdoulik merged 3 commits intodotnet:mainfrom Mar 10, 2026
Merged
[browser][coreclr] Fix corerun to run in browser again#125322radekdoulik merged 3 commits intodotnet:mainfrom
radekdoulik merged 3 commits intodotnet:mainfrom
Conversation
The corerun build uses -sEXPORT_ES6=1 -sMODULARIZE=1, producing corerun.js as an ES6 module. Three issues prevented it from running in the browser: 1. corerun.html loaded corerun.js with a plain <script> tag, causing "Cannot use import.meta outside a module". Fixed by using <script type="module"> with an ES6 import of the selfRun export. 2. libCorerun.extpost.js had 'var fetch = fetch || undefined' which in ES6 module scope shadows the global fetch API due to hoisting, breaking WASM loading. Removed the declaration. Also guarded process.exit() for Node.js only and made selfRun() auto-run only in Node.js (in browser it is called from corerun.html with config). 3. The preRun callback used bare FS/ENV globals which don't exist in modularized output. Fixed by accessing them via the module parameter. Additionally, Emscripten's --preload-file data is loaded by an async preRun callback whose fetch hasn't completed when our preRun runs. Fixed by using addRunDependency/monitorRunDependencies to defer main() until the preloaded files are available in the virtual FS. Also added ENV to EXPORTED_RUNTIME_METHODS so preRun can set APP_ASSEMBLIES via module.ENV.
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/runtime-infrastructure |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the CoreCLR corerun WASM host so the ES6-modularized corerun.js can run in a browser again (in addition to Node), aligning corerun.html and the JS glue code with Emscripten’s -sEXPORT_ES6=1 -sMODULARIZE=1 output.
Changes:
- Update
corerun.htmlto loadcorerun.jsas an ES module and call the exportedselfRun()with a module config. - Adjust
libCorerun.extpost.jsto avoid shadowing globalfetch, and to only auto-run / callprocess.exit()in Node. - Add a browser-specific Emscripten JS library (
libCorerun.browser.js) and exportENVso browserpreRuncan setAPP_ASSEMBLIES.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/hosts/corerun/wasm/libCorerun.extpost.js | Makes selfRun() configurable and Node-only auto-run; avoids fetch shadowing in ES module scope. |
| src/coreclr/hosts/corerun/wasm/libCorerun.browser.js | Provides a browser-only Emscripten library variant without Node FS dependencies. |
| src/coreclr/hosts/corerun/wasm/corerun.html | Loads corerun.js as an ES module and invokes selfRun() with browser config + preload dependency gating. |
| src/coreclr/hosts/corerun/CMakeLists.txt | Switches JS library based on CORERUN_IN_BROWSER and exports ENV for runtime config. |
…and add WASM_PRELOAD_DIR requirements
maraf
approved these changes
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The corerun build uses -sEXPORT_ES6=1 -sMODULARIZE=1, producing corerun.js as an ES6 module. Several issues prevented it from running in the browser:
corerun.html loaded corerun.js with a plain <script> tag, causing
<script type="module"> with an ES6 import of the selfRun export."Cannot use import.meta outside a module". Fixed by using
libCorerun.extpost.js had 'var fetch = fetch || undefined' which
in ES6 module scope shadows the global fetch API due to hoisting,
breaking WASM loading. Removed the declaration. Also guarded
process.exit() for Node.js only and made selfRun() auto-run only
in Node.js (in browser it is called from corerun.html with config).
The preRun callback used bare FS/ENV globals which don't exist in
modularized output. Fixed by accessing them via the module parameter.
Additionally, Emscripten's --preload-file data is loaded by an async
preRun callback whose fetch hasn't completed when our preRun runs.
Fixed by using addRunDependency/monitorRunDependencies to defer
main() until the preloaded files are available in the virtual FS.
libCorerun.js unconditionally depended on $NODEFS/$NODERAWFS which
are unavailable in browser builds. Use LibraryManager.library checks
to conditionally include them only when present.
Also added ENV to EXPORTED_RUNTIME_METHODS so the preRun callback can
set APP_ASSEMBLIES via module.ENV.