From 9d10fbc522765ce147fef9e6b111f8bee10d1b2b Mon Sep 17 00:00:00 2001 From: koe Date: Wed, 15 Jan 2025 00:17:38 -0600 Subject: [PATCH] bugfix: webtransport_is_available_with_cert_hashes() now detects if in a buggy Firefox version --- CHANGELOG.md | 4 ++++ renet2_netcode/Cargo.toml | 2 ++ .../client/availability_utils.rs | 22 ++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f82e2fb5..3b20576c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.1.1 - 01/15/25 + +- Fix `webtransport_is_available_with_cert_hashes()` to detect if in a buggy Firefox version. See https://phabricator.services.mozilla.com/D231479 + ## 0.1.0 - 12/23/24 - Update `renet2` sub-crate dependencies. diff --git a/renet2_netcode/Cargo.toml b/renet2_netcode/Cargo.toml index 5143f2fa..4620b444 100644 --- a/renet2_netcode/Cargo.toml +++ b/renet2_netcode/Cargo.toml @@ -162,6 +162,8 @@ features = [ "Event", "ErrorEvent", "BinaryType", + "Window", + "Navigator" ] [dev-dependencies] diff --git a/renet2_netcode/src/webtransport_socket/client/availability_utils.rs b/renet2_netcode/src/webtransport_socket/client/availability_utils.rs index 9120c569..bb1f187d 100644 --- a/renet2_netcode/src/webtransport_socket/client/availability_utils.rs +++ b/renet2_netcode/src/webtransport_socket/client/availability_utils.rs @@ -16,7 +16,7 @@ pub fn webtransport_is_available() -> bool { /// /// See [`webtransport_is_available`] if you don't care about cert hashes. pub fn webtransport_is_available_with_cert_hashes() -> bool { - webtransport_is_available_impl(true) + !buggy_firefox_version() && webtransport_is_available_impl(true) } fn webtransport_is_available_impl(with_cert_hashes: bool) -> bool { @@ -32,3 +32,23 @@ fn webtransport_is_available_impl(with_cert_hashes: bool) -> bool { // - https://developer.mozilla.org/en-US/docs/Web/API/WebTransport/WebTransport#exceptions WebTransport::new_with_options(url.as_str(), &config.wt_options()).is_ok() } + +// Note: this test can fail if the user modified their firefox user-agent string from the default. +fn buggy_firefox_version() -> bool { + // Firefox workaround for bug in v133-?. + // TODO: update this to filter on the correct version range when the bug is fixed + if let Some(window) = web_sys::window() { + if let Ok(user_agent_str) = window.navigator().user_agent() { + if let Some((_, firefox)) = user_agent_str.split_once("Firefox/") { + if let Some(version) = firefox.get(0..=4) { + if let Ok(version) = version.parse::() { + if version >= 133.0 { + return true; + } + } + } + } + } + } + false +}