Instead of assuming the base URL is always `window.location.origin`, infer it from `window.location.href`.