a-b-street/abstreet · error · anyhow::Error
Unsupported on web
Error message
Unsupported on web
What it means
get_clipboard is only implemented for native targets; on wasm32 the function unconditionally bails with "Unsupported on web". The browser clipboard API is not wired up in this library, so any wasm build calling this will always fail. It is a deliberate platform limitation, not a runtime fault.
Solutions
- Gate the call with #[cfg(not(target_arch = "wasm32"))] and provide a web alternative using navigator.clipboard.readText()
- Use cfg! or a trait to supply a platform-specific clipboard implementation
- Disable the paste-from-clipboard UI affordance in the web build
- Return an empty string / show a 'not supported on web' message to the user
Example fix
// before let text = get_clipboard()?; // after #[cfg(target_arch = "wasm32")] let text = String::new(); // or use wasm bindgen clipboard API #[cfg(not(target_arch = "wasm32"))] let text = get_clipboard()?;
Defensive patterns
Strategy: type-guard
Validate before calling
let supported = cfg!(not(target_arch = "wasm32"));
Type guard
fn clipboard_supported() -> bool {
cfg!(not(target_arch = "wasm32"))
} Try / catch
if cfg!(target_arch = "wasm32") {
// use navigator.clipboard.readText() via wasm-bindgen instead
} else {
let text = get_clipboard()?;
} Prevention
- Feature-gate clipboard calls with cfg(target_arch)
- Provide a web implementation using navigator.clipboard
- Hide copy/paste-from-clipboard UI in the web build
- Centralize platform capabilities in one helper instead of scattering cfgs
When it happens
Trigger: Calling widgetry::tools::get_clipboard() from any code compiled to wasm32 (the web build of the app).
Common situations: Shared code that pastes from clipboard runs unmodified in the browser build; feature-gating was forgotten when porting desktop functionality to web.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13).
Data as JSON: /api/errors/a926de21c15c0db1.
Report an issue: GitHub.
Appendix: source
Thrown at widgetry/src/tools/mod.rs:132
pub fn get_clipboard() -> Result<String> {
#[cfg(not(target_arch = "wasm32"))]
{
use clipboard::{ClipboardContext, ClipboardProvider};
// TODO The clipboard crate uses old nightly Errors. Converting to anyhow is weird.
let mut ctx: ClipboardContext = match ClipboardProvider::new() {
Ok(ctx) => ctx,
Err(err) => bail!("{}", err),
};
let contents = match ctx.get_contents() {
Ok(contents) => contents,
Err(err) => bail!("{}", err),
};
Ok(contents)
}
#[cfg(target_arch = "wasm32")]
{
bail!("Unsupported on web");
}
}
View on GitHub (pinned to 0964f29315)