{"record":{"id":"bd1026fa137248aa","repo":"a-b-street/abstreet","slug":"window-location-set-href-failed","errorCode":null,"errorMessage":"window.location.set_href failed","messagePattern":"window\\.location\\.set_href failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"map_gui/src/tools/title_screen.rs","lineNumber":243,"sourceCode":"                Transition::Push(PopupMsg::new_state(ctx, \"Error\", vec![err.to_string()]))\n            }\n\n            // On Windows, all we can do is open a new child process. Not sure how to end the\n            // current or detach.\n            #[cfg(windows)]\n            {\n                abstutil::must_run_cmd(Command::new(binary).args(args));\n                Transition::Keep\n            }\n        }\n\n        // On web, leave the current page and go to another.\n        #[cfg(target_arch = \"wasm32\")]\n        {\n            fn set_href(url: &str) -> anyhow::Result<()> {\n                let window = web_sys::window().ok_or(anyhow!(\"no window?\"))?;\n                window.location().set_href(url).map_err(|err| {\n                    anyhow!(err\n                        .as_string()\n                        .unwrap_or(\"window.location.set_href failed\".to_string()))\n                })\n            }\n\n            let page = match self {\n                Executable::ABStreet => \"abstreet\",\n                Executable::FifteenMin => \"fifteen_min\",\n                Executable::OSMViewer => \"osm_viewer\",\n                // This only works on native\n                Executable::ParkingMapper => unreachable!(),\n                Executable::Santa => \"santa\",\n                Executable::RawMapEditor => \"map_editor\",\n                Executable::LTN => \"ltn\",\n            };\n            let url = format!(\"{}.html{}\", page, abstutil::args_to_query_string(args));\n            if let Err(err) = set_href(&url) {\n                return Transition::Push(PopupMsg::new_state(","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/map_gui/src/tools/title_screen.rs#L225-L261","documentation":"set_href calls window.location().set_href(url), which returns a Result<JsValue> that resolves after the browser attempts navigation; failure is a JsValue converted with as_string(), falling back to \"window.location.set_href failed\" if the error isn't a string. This means the browser refused the navigation request.","triggerScenarios":"Calling set_href with a URL the browser blocks: invalid URL format, cross-origin navigation blocked in sandboxed iframes, or a popup/iframe sandbox without allow-top-navigation.","commonSituations":"App embedded in a sandboxed iframe attempting top-level navigation; malformed hand-built URL (missing scheme); browser extension or CSP blocking navigation.","solutions":["Verify the URL is absolute and well-formed (include https:// scheme)","Ensure the iframe sandbox permits top navigation (allow-top-navigation) or open in a new tab with window.open instead","Check browser console for the underlying JS error","Avoid building URLs with unencoded special characters"],"exampleFix":"// before\nset_href(\"abst://myapp\")?;\n// after\nset_href(\"https://abstreet.org/myapp.html\")?;","handlingStrategy":"try-catch","validationCode":"// validate the URL before navigation\nnew URL(url); // throws in JS if malformed\nif (!url.startsWith('http')) throw new Error('set_href needs an absolute URL');","typeGuard":null,"tryCatchPattern":"match set_href(url) {\n    Ok(_) => {},\n    Err(e) => log::error!(\"set_href failed: {:?}\", e), // inspect browser console too\n}","preventionTips":["Always navigate to absolute, well-formed URLs","Avoid iframe sandbox attributes that block top navigation","Test embedded deployments (iframes) separately from top-level pages"],"tags":["wasm","browser-api","navigation","url"],"backgroundTag":"invalid-url","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}