-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[browser] Unnecessary browser and node calls breaking usage in restricted environments #91558
Comments
Tagging subscribers to this area: @dotnet/area-meta Issue DetailsDescriptionI'm trying to build .NET 8 library for VS Code web extension, where neither browser APIs (window/document), nor node modules are available. Previously (in .NET 6) I had to strip generated JS wrapper from various unconditional usages of such APIs. I hoped in .NET 8 it's solved (and I can see lots of changes in this direction), but unfortunately there are stilll issues. For example,
Is it possible to guard browser/node-specific calls like this for .NET 8? Reproduction StepsInstall the VS Code extension and notice Remove Expected behaviorNo calls to browser or node-specific APIs (eg, Actual behaviorBrowser and node-specific APIs are used even when all the required dotnet assets are specified in config. Regression?No response Known WorkaroundsNo response Configuration.NET 8.0.0-rc.2.23431.9 Other informationNo response
|
Trying to find the culprit in the sources, but stuck here: https://github.com/dotnet/runtime/blob/main/src/mono/wasm/runtime/es6/dotnet.es6.lib.js#L60 There are no other " _scriptDir" vars in the codebase, so it must be it, but not sure where |
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsDescriptionI'm trying to build .NET 8 library for VS Code web extension, where neither browser APIs (window/document), nor node modules are available. Previously (in .NET 6) I had to strip generated JS wrapper from various unconditional usages of such APIs. I hoped in .NET 8 it's solved (and I can see lots of changes in this direction), but unfortunately there are stilll issues. For example,
Is it possible to guard browser/node-specific calls like this for .NET 8? Reproduction StepsInstall the VS Code extension and notice Remove Expected behaviorNo calls to browser or node-specific APIs (eg, Actual behaviorBrowser and node-specific APIs are used even when all the required dotnet assets are specified in config. Regression?No response Known WorkaroundsNo response Configuration.NET 8.0.0-rc.2.23431.9 Other informationNo response
|
But that would make it node incompatible. For the |
I hope we can me it work in both node, browser and restricted environments w/o special builds for each. This is already working on my end with those 3 modifications I've mentioned above.
Yeah, that was essential, but not enough for VS Code, unfortunately (sorry I wasn't able to test at the time, had to rewrite the whole library for .NET 8 and new interop). If those 3 calls to |
Could you please point me to more details about VS Code constraints ? Documentation ? |
Here: https://code.visualstudio.com/api/extension-guides/web-extensions#migrate-extension-with-code Due to V8 cache not available on node (and dotnet runtime requiring it), we also have to use the web format for standalone VS Code environment. Basically, we can't use any import/require, except the pre-defined |
Cache API ? This should disable it.
|
Presumably it's something about v8 code caching: https://v8.dev/blog/code-caching I didn't really investigate it properly. Just had |
Could you please update the top level description and list specific offenders ? That would make at least some of them more actionable. |
Done. Thanks for looking into this! |
Migrated into #80045 |
I'm trying to build .NET 8 library for VS Code web extension, where neither browser APIs (window/document), nor node modules are available. Previously (in .NET 6) I had to strip generated JS wrapper from various unconditional usages of such APIs. I hoped in .NET 8 it's solved (and I can see lots of changes in this direction), but unfortunately there are stilll issues. For example,
createDotnetRuntime
function has following (from bundled library sources, so it's bit mangled):document
is undefined in VS Code andrequire('url')
causes exception. I'm injecting all the requires resources (runtime.wasm, dotnet.runtime.js, etc) via the assets in config, so no IO should be required to boot the runtime.Is it possible to guard browser/node-specific calls like this for .NET 8?
The Specific Offenders in .NET 8
Here is the link to the patch I'm using to strip all the offenders: https://github.com/elringus/bootsharp/blob/main/src/cs/Bootsharp.Publish/Pack/ModulePatcher/InternalPatcher.cs After the patch, bundlers are only complaining about
module
andprocess
unresolved externals (tested with webpack, rollup, esbuild, vite) and the bundled runtime is working in browsers, node, deno, bun and VS Code web extensions.Regarding
module
andprocess
— would be optimal to guard them as well, though I wasn't able to find a straightforward way to do that (conditional usage still trigger bundlers). As a workaround, I'm marking them as global (eg,-g process,module
in rollup), which seem to satisfy the bundlers.The text was updated successfully, but these errors were encountered: