iroh to your browser project’s dependencies and keep building it using wasm-bindgen.
For end-to-end examples of integrating iroh into a browser page, see these examples on our iroh-examples repository:
- An iroh echo server in the browser. Check it out in action
- An browser chat room UI based on the iroh gossip chat example. Check it out in action
Limitations
When you’re in a browser context - as opposed to in a native app or on desktop, you’re in a strict “sandbox” that disallows a few things iroh relies upon, e.g. sending UDP packets directly. Thus, we need to work around these limitations and can’t provide you with the full magic of iroh just yet. We envision that most applications will use iroh browser support as an additional feature to complement existing deployments to desktops, native apps or servers, where they’ll be able to make use of everything that iroh offers.No direct connections
All connections from browsers to somewhere else need to flow via a relay server. This is because we can’t port our hole-punching logic in iroh to browsers: They don’t support sending UDP packets to IP addresses from inside the browser sandbox. Keep in mind that connections are end-to-end encrypted, as always with iroh. So even though traffic from browsers is always relayed, it can’t be decrypted by the relay. There are other ways of getting direct connections going, such as WebTransport withserverCertificateHashes, or WebRTC. We may expand iroh’s browser support
to make use of these to try to generate direct connections even when a browser
node is involved in the connection.
iroh crate features
As of iroh version 0.33, you need to disable all optional features on iroh for the Wasm build to succeed.
To do so, depend on iroh via iroh = { version = "0.33", default-features = false }.
This will install a version of iroh with default features, except it doesn’t track metrics locally.
We’ll get rid of this limitation very soon (likely with iroh version 0.34).
Non-default features like discovery-local-network or discovery-dht will likely never be available in browsers, unless browser APIs making them possible are added.