From 556bcd98730274da0f671eb5df9e63ec9ad11068 Mon Sep 17 00:00:00 2001 From: gngpp Date: Fri, 20 Nov 2026 14:43:18 +0800 Subject: [PATCH 1/2] feat(emulate): add Opera 132 through 140 profiles --- README.md | 6 +- crates/wreq-util/src/emulate.rs | 9 + .../wreq-util/src/emulate/profile/chrome.rs | 13 +- .../src/emulate/profile/chrome/tls.rs | 50 ++++-- crates/wreq-util/src/emulate/profile/opera.rs | 169 ++++++++++++++++++ crates/wreq-util/tests/client.rs | 43 ++++- crates/wreq-util/tests/emulate_opera.rs | 24 +++ lib/wreq_ruby/emulate.rb | 9 + src/emulate.rs | 9 + test/emulation_test.rb | 10 ++ 10 files changed, 314 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 67fd3b8..4c84f91 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,10 @@ Most browser device models share identical TLS and HTTP/2 configurations, differ | **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134`, `Edge135`, `Edge136`, `Edge137`, `Edge138`, `Edge139`, `Edge140`, `Edge141`, `Edge142`, `Edge143`, `Edge144`, `Edge145`, `Edge146`, `Edge147`, `Edge148` | | **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151`, `Firefox152` | | **Safari** | `Safari15_3`, `Safari15_5`, `Safari15_6_1`, `Safari16`, `Safari16_5`, `Safari17_0`, `Safari17_2_1`, `Safari17_4_1`, `Safari17_5`, `Safari17_6`, `Safari18`, `Safari18_2`, `Safari18_3`, `Safari18_3_1`, `Safari18_5`, `Safari26`, `Safari26_1`, `Safari26_2`, `SafariIos16_5`, `SafariIos17_2`, `SafariIos17_4_1`, `SafariIos18_1_1`, `SafariIos26`, `SafariIos26_2`, `SafariIPad18`, `SafariIPad26`, `SafariIpad26_2` | - | **OkHttp** | `Opera116`, `Opera117`, `Opera118`, `Opera119`, `Opera120`, `Opera121`, `Opera122`, `Opera123`, `Opera124`, `Opera125`, `Opera126`, `Opera127`, `Opera128`, `Opera129`, `Opera130` | - | **Opera** | `Opera116`, `Opera117`, `Opera118`, `Opera119` | + | **OkHttp** | `OkHttp3_9`, `OkHttp3_11`, `OkHttp3_13`, `OkHttp3_14`, `OkHttp4_9`, `OkHttp4_10`, `OkHttp4_12`, `OkHttp5` | + | **Opera** | `Opera116`–`Opera140` | + + Opera 132–140 use the corresponding Chromium desktop TLS and HTTP/2 defaults with Opera-branded request headers. diff --git a/crates/wreq-util/src/emulate.rs b/crates/wreq-util/src/emulate.rs index f248c03..7cb9384 100644 --- a/crates/wreq-util/src/emulate.rs +++ b/crates/wreq-util/src/emulate.rs @@ -108,6 +108,15 @@ define_enum!( Opera129 => ("opera_129", opera129::emulation), Opera130 => ("opera_130", opera130::emulation), Opera131 => ("opera_131", opera131::emulation), + Opera132 => ("opera_132", opera132::emulation), + Opera133 => ("opera_133", opera133::emulation), + Opera134 => ("opera_134", opera134::emulation), + Opera135 => ("opera_135", opera135::emulation), + Opera136 => ("opera_136", opera136::emulation), + Opera137 => ("opera_137", opera137::emulation), + Opera138 => ("opera_138", opera138::emulation), + Opera139 => ("opera_139", opera139::emulation), + Opera140 => ("opera_140", opera140::emulation), // Firefox versions Firefox109 => ("firefox_109", ff109::emulation), diff --git a/crates/wreq-util/src/emulate/profile/chrome.rs b/crates/wreq-util/src/emulate/profile/chrome.rs index de31e96..ef3eca6 100644 --- a/crates/wreq-util/src/emulate/profile/chrome.rs +++ b/crates/wreq-util/src/emulate/profile/chrome.rs @@ -1,14 +1,15 @@ #[macro_use] mod http2; -#[macro_use] -mod tls; mod header; +pub(super) mod tls; use header::*; use tls::*; use super::*; +pub(super) use header::header_initializer_chrome155 as chromium_jxl_headers; + mod_generator!( v100, tls_options!(1), @@ -905,7 +906,7 @@ mod_generator!( mod_generator!( v132, - tls_options!(7, CURVES_3), + tls_options!(7), http2_options!(3), header_initializer_with_zstd_priority, [ @@ -1797,7 +1798,7 @@ mod_generator!( mod_generator!( v150, - tls_options!(8, CURVES_3, NEW_SIGALGS_LIST), + tls_options!(8), http2_options!(3), header_initializer_with_zstd_priority, [ @@ -1864,7 +1865,7 @@ mod_generator!( mod_generator!( v152, - tls_options!(9, CURVES_3), + tls_options!(9), http2_options!(3), header_initializer_chrome152, [ @@ -1931,7 +1932,7 @@ mod_generator!( mod_generator!( v154, - tls_options!(9, CURVES_3, sorted_trust_anchors()), + tls_options!(10), http2_options!(3), header_initializer_with_zstd_priority, [ diff --git a/crates/wreq-util/src/emulate/profile/chrome/tls.rs b/crates/wreq-util/src/emulate/profile/chrome/tls.rs index f189eb3..0d7a90c 100644 --- a/crates/wreq-util/src/emulate/profile/chrome/tls.rs +++ b/crates/wreq-util/src/emulate/profile/chrome/tls.rs @@ -32,39 +32,49 @@ macro_rules! tls_options { .pre_shared_key(true) .curves($curves)) }; - (7, $curves:expr) => { - tls_options!(@build ChromeTlsConfig::builder() + (7) => {{ + use $crate::emulate::profile::chrome::tls as chromium; + chromium::tls_options!(@build chromium::ChromeTlsConfig::builder() .permute_extensions(true) .enable_ech_grease(true) .pre_shared_key(true) - .curves($curves) + .curves(chromium::CURVES_3) .alps_use_new_codepoint(true)) - }; - (8, $curves:expr, $sigalgs:expr) => { - tls_options!(@build ChromeTlsConfig::builder() + }}; + (8) => {{ + use $crate::emulate::profile::chrome::tls as chromium; + chromium::tls_options!(@build chromium::ChromeTlsConfig::builder() .permute_extensions(true) .enable_ech_grease(true) .pre_shared_key(true) - .curves($curves) - .sigalgs_list($sigalgs) + .curves(chromium::CURVES_3) + .sigalgs_list(chromium::NEW_SIGALGS_LIST) .alps_use_new_codepoint(true)) - }; - (9, $curves:expr) => { - tls_options!(9, $curves, shuffled_trust_anchors(crate::rand::fast_random)) - }; - (9, $curves:expr, $trust_anchors:expr) => { - tls_options!(@build ChromeTlsConfig::builder() + }}; + (9) => {{ + use $crate::emulate::profile::chrome::tls as chromium; + chromium::tls_options!(@trust_anchors chromium::shuffled_trust_anchors($crate::rand::fast_random)) + }}; + (10) => {{ + use $crate::emulate::profile::chrome::tls as chromium; + chromium::tls_options!(@trust_anchors chromium::sorted_trust_anchors()) + }}; + (@trust_anchors $trust_anchors:expr) => {{ + use $crate::emulate::profile::chrome::tls as chromium; + chromium::tls_options!(@build chromium::ChromeTlsConfig::builder() .permute_extensions(true) .enable_ech_grease(true) .pre_shared_key(true) - .curves($curves) - .sigalgs_list(NEW_SIGALGS_LIST) + .curves(chromium::CURVES_3) + .sigalgs_list(chromium::NEW_SIGALGS_LIST) .trust_anchors($trust_anchors) .grease_sigalgs_enabled(true) .alps_use_new_codepoint(true)) - }; + }}; } +pub(in crate::emulate::profile) use tls_options; + pub const CURVES_1: &str = join!(":", "X25519", "P-256", "P-384"); pub const CURVES_2: &str = join!(":", "X25519Kyber768Draft00", "X25519", "P-256", "P-384"); pub const CURVES_3: &str = join!(":", "X25519MLKEM768", "X25519", "P-256", "P-384"); @@ -125,7 +135,9 @@ pub(super) const CHROME_TRUST_ANCHORS: &[u8] = &chromium_roots::encoded_trust_an // the root store's source order. Generate an order once per native configuration; // connections using that client configuration retain the order. // https://chromium.googlesource.com/chromium/src/+/f7b831a4e249fbd98eae4b391c69f70300a849d1/net/ssl/ssl_config_service.cc -pub(super) fn shuffled_trust_anchors(mut random: impl FnMut() -> u64) -> Vec { +pub(in crate::emulate::profile) fn shuffled_trust_anchors( + mut random: impl FnMut() -> u64, +) -> Vec { let mut ids = chromium_roots::trust_anchor_ids(); for index in (1..ids.len()).rev() { let bound = (index + 1) as u64; @@ -142,7 +154,7 @@ pub(super) fn shuffled_trust_anchors(mut random: impl FnMut() -> u64) -> Vec // Chrome 154 sorts the raw IDs before adding their length prefixes. // https://chromium.googlesource.com/chromium/src/+/731082f0a26ce4b3976c3d82943092f5d13daf13/net/cert/x509_util.cc -pub(super) fn sorted_trust_anchors() -> Vec { +pub(in crate::emulate::profile) fn sorted_trust_anchors() -> Vec { let mut ids = chromium_roots::trust_anchor_ids(); ids.sort_unstable(); encode_trust_anchors(&ids) diff --git a/crates/wreq-util/src/emulate/profile/opera.rs b/crates/wreq-util/src/emulate/profile/opera.rs index c751d39..a08bc80 100644 --- a/crates/wreq-util/src/emulate/profile/opera.rs +++ b/crates/wreq-util/src/emulate/profile/opera.rs @@ -7,6 +7,7 @@ mod header; use header::*; use tls::*; +use super::chrome::chromium_jxl_headers; use super::*; mod_generator!( @@ -297,3 +298,171 @@ mod_generator!( ) ] ); + +// Reuse Chromium's TLS defaults with Opera's existing HTTP/2 settings. +// Brand hints use Chromium's milestone seed with Opera as the product brand. +mod_generator!( + opera132, + chrome::tls::tls_options!(7), + http2_options!(), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="148", "Opera";v="132", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 OPR/132.0.0.0" + ), + ( + Windows, + r#""Chromium";v="148", "Opera";v="132", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 OPR/132.0.0.0" + ) + ] +); + +mod_generator!( + opera133, + opera132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Opera";v="133", "Chromium";v="149", "Not)A;Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0" + ), + ( + Windows, + r#""Opera";v="133", "Chromium";v="149", "Not)A;Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0" + ) + ] +); + +mod_generator!( + opera134, + chrome::tls::tls_options!(8), + http2_options!(), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not;A=Brand";v="8", "Chromium";v="150", "Opera";v="134""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 OPR/134.0.0.0" + ), + ( + Windows, + r#""Not;A=Brand";v="8", "Chromium";v="150", "Opera";v="134""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 OPR/134.0.0.0" + ) + ] +); + +mod_generator!( + opera135, + opera134::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not=A?Brand";v="99", "Opera";v="135", "Chromium";v="151""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36 OPR/135.0.0.0" + ), + ( + Windows, + r#""Not=A?Brand";v="99", "Opera";v="135", "Chromium";v="151""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36 OPR/135.0.0.0" + ) + ] +); + +mod_generator!( + opera136, + chrome::tls::tls_options!(9), + http2_options!(), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="152", "Not?A_Brand";v="24", "Opera";v="136""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36 OPR/136.0.0.0" + ), + ( + Windows, + r#""Chromium";v="152", "Not?A_Brand";v="24", "Opera";v="136""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36 OPR/136.0.0.0" + ) + ] +); + +mod_generator!( + opera137, + opera136::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Opera";v="137", "Not_A Brand";v="8", "Chromium";v="153""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36 OPR/137.0.0.0" + ), + ( + Windows, + r#""Opera";v="137", "Not_A Brand";v="8", "Chromium";v="153""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36 OPR/137.0.0.0" + ) + ] +); + +mod_generator!( + opera138, + chrome::tls::tls_options!(10), + http2_options!(), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="154", "Opera";v="138", "Not A(Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36 OPR/138.0.0.0" + ), + ( + Windows, + r#""Chromium";v="154", "Opera";v="138", "Not A(Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36 OPR/138.0.0.0" + ) + ] +); + +mod_generator!( + opera139, + opera138::build_emulation, + chromium_jxl_headers, + [ + ( + MacOS, + r#""Opera";v="139", "Chromium";v="155", "Not(A:Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36 OPR/139.0.0.0" + ), + ( + Windows, + r#""Opera";v="139", "Chromium";v="155", "Not(A:Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36 OPR/139.0.0.0" + ) + ] +); + +mod_generator!( + opera140, + opera138::build_emulation, + chromium_jxl_headers, + [ + ( + MacOS, + r#""Not-A.Brand";v="99", "Opera";v="140", "Chromium";v="157""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/140.0.0.0" + ), + ( + Windows, + r#""Not-A.Brand";v="99", "Opera";v="140", "Chromium";v="157""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/140.0.0.0" + ) + ] +); diff --git a/crates/wreq-util/tests/client.rs b/crates/wreq-util/tests/client.rs index 3881397..d8fbbac 100644 --- a/crates/wreq-util/tests/client.rs +++ b/crates/wreq-util/tests/client.rs @@ -95,7 +95,11 @@ async fn assert_emulation_headers(profile: Profile, expected: &'static [&'static #[tokio::test] async fn test_client_emulation_device() { let server = server::http(move |req| async move { - let header = |name| req.headers().get(name).and_then(|value| value.to_str().ok()); + let header = |name| { + req.headers() + .get(name) + .and_then(|value| value.to_str().ok()) + }; assert_eq!( header("user-agent"), @@ -145,3 +149,40 @@ async fn test_firefox_default_header_order() { async fn test_opera_default_header_order() { assert_emulation_headers(Emulation::Opera116, CHROMIUM_HEADER_ORDER).await; } + +#[tokio::test] +async fn test_opera140_desktop_headers() { + let server = server::http(move |request| async move { + let headers = request.headers(); + assert_eq!( + headers["user-agent"], + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/140.0.0.0" + ); + assert_eq!( + headers["sec-ch-ua"], + r#""Not-A.Brand";v="99", "Opera";v="140", "Chromium";v="157""# + ); + assert!( + headers["accept"] + .to_str() + .unwrap() + .contains("image/jxl,image/avif") + ); + http::Response::default() + }); + + let response = Client::builder() + .emulation( + Emulation::builder() + .profile(Emulation::Opera140) + .platform(Platform::Windows) + .build(), + ) + .build() + .unwrap() + .get(format!("http://{}/", server.addr())) + .send() + .await + .unwrap(); + assert_eq!(response.status(), wreq::StatusCode::OK); +} diff --git a/crates/wreq-util/tests/emulate_opera.rs b/crates/wreq-util/tests/emulate_opera.rs index 3d8e3c2..c55dd66 100644 --- a/crates/wreq-util/tests/emulate_opera.rs +++ b/crates/wreq-util/tests/emulate_opera.rs @@ -111,3 +111,27 @@ test_emulation!( ["t13d1516h2_8daaf6152771_02713d6af862"], "52d84b11737d980aef856699f885ca86" ); + +test_emulation!( + test_opera132, + Emulation::Opera132, + ["t13d1516h2_8daaf6152771_d8a2da3f94cd"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera134, + Emulation::Opera134, + ["t13d1516h2_8daaf6152771_806a8c22fdea"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera140, + Emulation::Opera140, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); diff --git a/lib/wreq_ruby/emulate.rb b/lib/wreq_ruby/emulate.rb index 661940d..70afd48 100644 --- a/lib/wreq_ruby/emulate.rb +++ b/lib/wreq_ruby/emulate.rb @@ -168,6 +168,15 @@ class Profile Opera129 = nil Opera130 = nil Opera131 = nil + Opera132 = nil + Opera133 = nil + Opera134 = nil + Opera135 = nil + Opera136 = nil + Opera137 = nil + Opera138 = nil + Opera139 = nil + Opera140 = nil end unless method_defined?(:to_s) diff --git a/src/emulate.rs b/src/emulate.rs index bb3d45d..4a8cfcc 100644 --- a/src/emulate.rs +++ b/src/emulate.rs @@ -189,6 +189,15 @@ define_ruby_enum!( Opera129, Opera130, Opera131, + Opera132, + Opera133, + Opera134, + Opera135, + Opera136, + Opera137, + Opera138, + Opera139, + Opera140, ); // Defines constant registration, `into_ffi`/`from_ffi`, and handlers for diff --git a/test/emulation_test.rb b/test/emulation_test.rb index 5384458..02cfc01 100644 --- a/test/emulation_test.rb +++ b/test/emulation_test.rb @@ -54,6 +54,16 @@ def test_new_browser_profiles_are_available end end + def test_opera_132_through_140_profiles_are_available + (132..140).each do |version| + name = "Opera#{version}" + assert Wreq::Profile.const_defined?(name, false), "missing #{name}" + profile = Wreq::Profile.const_get(name, false) + assert_equal name, profile.to_s + assert_instance_of Wreq::Emulation, Wreq::Emulation.new(profile: profile) + end + end + def test_all_emulation_os_constants_are_non_nil Wreq::Platform.constants.each do |name| const = Wreq::Platform.const_get(name) From 7940054926957b52102278b1059c323bdfc0573f Mon Sep 17 00:00:00 2001 From: gngpp Date: Fri, 20 Nov 2026 14:52:43 +0800 Subject: [PATCH 2/2] test(emulate): cover every Opera profile --- test/emulation_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/emulation_test.rb b/test/emulation_test.rb index 02cfc01..07b98a1 100644 --- a/test/emulation_test.rb +++ b/test/emulation_test.rb @@ -54,8 +54,8 @@ def test_new_browser_profiles_are_available end end - def test_opera_132_through_140_profiles_are_available - (132..140).each do |version| + def test_all_opera_profiles_are_available + (116..140).each do |version| name = "Opera#{version}" assert Wreq::Profile.const_defined?(name, false), "missing #{name}" profile = Wreq::Profile.const_get(name, false)