Dart can target browser JavaScript and WebAssembly, but VM-only libraries such as dart:io do not become browser APIs. Keep platform-specific adapters behind a portable contract so your business logic can be tested independently.
Use the current interop approach
Use dart:js_interop for JavaScript declarations and package:web for browser APIs. Legacy dart:html/dart:js-style code is not the portable route for modern Wasm targets. The
JS interop guide
documents the current static API boundary.
import 'dart:js_interop';
@JS('console.log')
external void browserLog(JSString message);
void main() {
browserLog('Invoice workspace ready'.toJS);
}
This complete source targets a browser JS environment with console.log. It is not a native VM entry point. In a suitable web package, compile and serve it through the current Dart web workflow, then inspect the browser console.
Keep conversions visible
JSString and Dart String are different static types, and conversions are part of the boundary. A declaration must match the real JavaScript API shape. An external member is a promise about an implementation outside Dart, not an automatically implemented Dart function.
Plan WebAssembly deliberately
Check every dependency’s compatibility, initialization and browser support. Verify the runtime actually received before drawing performance conclusions. Minimize hot-loop crossings between JS and Dart and test a real served build; file URLs do not reproduce hosted module behavior.
The Flutter web path covers application layout and deployment when the client is Flutter. A Dart document-oriented site and a Flutter application canvas solve different product needs.
Exercise
Wrap one browser API behind a small Dart interface and supply a fake for business-logic tests. Compile for the intended web target and check the actual host API. Explain why the same source cannot simply import dart:io and run unchanged in a browser.