Skip to content

Commit

Permalink
feat: port upstream code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vanetix committed Oct 10, 2024
1 parent 34b893e commit e4d4ca3
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 22 deletions.
15 changes: 14 additions & 1 deletion src/client_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct ClientHint {
pub platform_version: Option<String>,
pub full_version_list: Vec<(String, String)>,
pub app: Option<String>,
pub form_factors: Vec<String>,
}

impl ClientHint {
Expand All @@ -59,12 +60,15 @@ impl ClientHint {
let mut platform = None;
let mut platform_version = None;
let mut app = None;

let mut form_factors: Vec<String> = Vec::new();
let mut full_version_list: Vec<(String, String)> = Vec::new();

static BRAND_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r#""([^"]+)"; ?v="([^"]+)"?"#).unwrap());

static FORM_FACTOR_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"~"([a-z]+)"~i"#).unwrap());

// println!("headers: {:?}", headers);
for (header, value) in headers {
let header = header.replace('_', "-").to_lowercase();
Expand Down Expand Up @@ -137,6 +141,14 @@ impl ClientHint {
full_version_list.push((brand.to_owned(), brand_version.to_owned()));
}
}

"sec-ch-ua-form-factors" => {
form_factors = FORM_FACTOR_REGEX
.captures_iter(&value)
.filter_map(|x| x.ok()?.get(1).map(|x| x.as_str().to_lowercase()))
.collect();
}

_ => {}
}
}
Expand All @@ -151,6 +163,7 @@ impl ClientHint {
platform_version,
full_version_list,
app,
form_factors,
};

// println!("client hints: {:?}", res);
Expand Down
65 changes: 52 additions & 13 deletions src/known_browsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn available_browsers() -> HashMap<String, String> {
("4A", "Acoo Browser"),
("BW", "AdBlock Browser"),
("A7", "Adult Browser"),
("8A", "Ai Browser"),
("A9", "Airfind Secure Browser"),
("AF", "ANT Fresco"),
("AG", "ANTGalio"),
Expand All @@ -140,6 +141,7 @@ fn available_browsers() -> HashMap<String, String> {
("A4", "AOL Shield Pro"),
("2A", "Aplix"),
("A6", "AppBrowzer"),
("0A", "AppTec Secure Browser"),
("AP", "APUS Browser"),
("AR", "Arora"),
("AX", "Arctic Fox"),
Expand All @@ -148,6 +150,7 @@ fn available_browsers() -> HashMap<String, String> {
("PN", "APN Browser"),
("6A", "Arachne"),
("RA", "Arc"),
("R5", "Armorfly Browser"),
("AI", "Arvin"),
("AK", "Ask.com"),
("AU", "Asus Browser"),
Expand Down Expand Up @@ -193,6 +196,7 @@ fn available_browsers() -> HashMap<String, String> {
("BX", "BrowseX"),
("BZ", "Browzar"),
("B7", "Browlser"),
("M9", "Browser Mini"),
("4B", "BrowsBit"),
("BY", "Biyubi"),
("BF", "Byffox"),
Expand Down Expand Up @@ -237,6 +241,7 @@ fn available_browsers() -> HashMap<String, String> {
("C5", "Chromium GOST"),
("CY", "Cyberfox"),
("CS", "Cheshire"),
("8C", "Cromite"),
("RC", "Crow Browser"),
("CT", "Crusta"),
("CG", "Craving Explorer"),
Expand Down Expand Up @@ -309,6 +314,7 @@ fn available_browsers() -> HashMap<String, String> {
("FH", "Flash Browser"),
("FS", "Flast"),
("F5", "Flyperlink"),
("F9", "FOSS Browser"),
("FU", "FreeU"),
("F6", "Freedom Browser"),
("FT", "Frost"),
Expand All @@ -329,6 +335,7 @@ fn available_browsers() -> HashMap<String, String> {
("G2", "GO Browser"),
("RN", "GreenBrowser"),
("HW", "Habit Browser"),
("H7", "Halo Browser"),
("HB", "Harman Browser"),
("HS", "HasBrowser"),
("HA", "Hawk Turbo Browser"),
Expand All @@ -340,6 +347,7 @@ fn available_browsers() -> HashMap<String, String> {
("H4", "Holla Web Browser"),
("H5", "HotBrowser"),
("HJ", "HotJava"),
("H6", "HONOR Browser"),
("HT", "HTC Browser"),
("HU", "Huawei Browser Mobile"),
("HP", "Huawei Browser"),
Expand All @@ -364,10 +372,11 @@ fn available_browsers() -> HashMap<String, String> {
("I9", "Insta Browser"),
("IE", "Internet Explorer"),
("I7", "Internet Browser Secure"),
("5I", "Internet Webbrowser"),
("3I", "Intune Managed Browser"),
("I5", "Indian UC Mini Browser"),
("Z0", "InBrowser"),
("IG", "Involt Go"),
("IG", "Involta Go"),
("IM", "IE Mobile"),
("IR", "Iron"),
("JB", "Japan Browser"),
Expand All @@ -380,6 +389,7 @@ fn available_browsers() -> HashMap<String, String> {
("JZ", "JUZI Browser"),
("KB", "K.Browser"),
("KF", "Keepsafe Browser"),
("K7", "KeepSolid Browser"),
("KS", "Kids Safe Browser"),
("KI", "Kindle Browser"),
("KM", "K-meleon"),
Expand All @@ -404,7 +414,7 @@ fn available_browsers() -> HashMap<String, String> {
("LF", "LieBaoFast"),
("LG", "LG Browser"),
("LH", "Light"),
("L4", "lightning Browser Plus"),
("L4", "Lightning Browser Plus"),
("L1", "Lilo"),
("LI", "Links"),
("RI", "Liri Browser"),
Expand Down Expand Up @@ -434,7 +444,7 @@ fn available_browsers() -> HashMap<String, String> {
("M3", "Midori Lite"),
("M6", "MixerBox AI"),
("MO", "Mobicip"),
("MU", "MIUI Browser"),
("MU", "Mi Browser"),
("MS", "Mobile Silk"),
("MK", "Mogok Browser"),
("M8", "Motorola Internet Browser"),
Expand All @@ -443,6 +453,7 @@ fn available_browsers() -> HashMap<String, String> {
("MX", "Maxthon"),
("M4", "MaxTube Browser"),
("MA", "Maelstrom"),
("3M", "Mises"),
("MM", "Mmx Browser"),
("NM", "MxNitro"),
("MY", "Mypal"),
Expand All @@ -467,6 +478,7 @@ fn available_browsers() -> HashMap<String, String> {
("NP", "NetPositive"),
("NS", "Netscape"),
("WR", "NextWord Browser"),
("N8", "Ninesky"),
("NT", "NTENT Browser"),
("NU", "Nuanti Meta"),
("NI", "Nuviu"),
Expand All @@ -485,6 +497,7 @@ fn available_browsers() -> HashMap<String, String> {
("OL", "OnBrowser Lite"),
("OE", "ONE Browser"),
("N4", "Onion Browser"),
("1N", "ONIONBrowser"),
("Y1", "Opera Crypto"),
("OX", "Opera GX"),
("OG", "Opera Neon"),
Expand All @@ -506,41 +519,53 @@ fn available_browsers() -> HashMap<String, String> {
("O4", "Open Browser"),
("4U", "Open Browser 4U"),
("5G", "Open Browser fast 5G"),
("5O", "Open Browser Lite"),
("O7", "Open TV Browser"),
("OW", "OmniWeb"),
("OT", "Otter Browser"),
("4O", "Owl Browser"),
("JR", "OJR Browser"),
("PL", "Palm Blazer"),
("PM", "Pale Moon"),
("PY", "Polypane"),
("8P", "Prism"),
("PP", "Oppo Browser"),
("P6", "Opus Browser"),
("PR", "Palm Pre"),
("PU", "Puffin"),
("7I", "Puffin Cloud Browser"),
("6I", "Puffin Incognito Browser"),
("PU", "Puffin Secure Browser"),
("2P", "Puffin Web Browser"),
("PW", "Palm WebPro"),
("PA", "Palmscape"),
("P7", "Pawxy"),
("0P", "Peach Browser"),
("PE", "Perfect Browser"),
("K6", "Perk"),
("P1", "Phantom.me"),
("PH", "Phantom Browser"),
("PX", "Phoenix"),
("PB", "Phoenix Browser"),
("5P", "Photon"),
("N9", "Pintar Browser"),
("P9", "PirateBrowser"),
("P8", "PICO Browser"),
("PF", "PlayFree Browser"),
("PK", "PocketBook Browser"),
("PO", "Polaris"),
("PT", "Polarity"),
("LY", "PolyBrowser"),
("9P", "Presearch"),
("BP", "Privacy Browser"),
("PI", "PrivacyWall"),
("P4", "Privacy Explorer Fast Safe"),
("X5", "Privacy Pioneer Browser"),
("P3", "Private Internet Browser"),
("P5", "Proxy Browser"),
("7P", "Proxyium"),
("6P", "Proxynet"),
("2F", "ProxyFox"),
("2M", "ProxyMax"),
("P2", "Pi Browser"),
("P0", "PronHub Browser"),
("PC", "PSI Secure Browser"),
Expand All @@ -560,10 +585,12 @@ fn available_browsers() -> HashMap<String, String> {
("QU", "Quark"),
("QZ", "QupZilla"),
("QM", "Qwant Mobile"),
("Q5", "QtWeb"),
("QW", "QtWebEngine"),
("R3", "Rakuten Browser"),
("R4", "Rakuten Web Search"),
("R2", "Raspbian Chromium"),
("RT", "RCA Tor Explorer"),
("RE", "Realme Browser"),
("RK", "Rekonq"),
("RM", "RockMelt"),
Expand Down Expand Up @@ -611,6 +638,7 @@ fn available_browsers() -> HashMap<String, String> {
("LE", "Smart Lenovo Browser"),
("OZ", "Smooz"),
("SN", "Snowshoe"),
("K5", "Spark"),
("B1", "Spectre Browser"),
("S2", "Splash"),
("SI", "Sputnik Browser"),
Expand Down Expand Up @@ -648,10 +676,14 @@ fn available_browsers() -> HashMap<String, String> {
("TI", "Tint Browser"),
("TL", "TrueLocation Browser"),
("TC", "TUC Mini Browser"),
("TK", "TUSK"),
("TU", "Tungsten"),
("TG", "ToGate"),
("T3", "Total Browser"),
("TQ", "TQ Browser"),
("TS", "TweakStyle"),
("TV", "TV Bro"),
("T4", "TV-Browser Internet"),
("U0", "U Browser"),
("UB", "UBrowser"),
("UC", "UC Browser"),
Expand All @@ -666,6 +698,7 @@ fn available_browsers() -> HashMap<String, String> {
("V0", "vBrowser"),
("VA", "Vast Browser"),
("V3", "VD Browser"),
("VR", "Veera"),
("VE", "Venus Browser"),
("WD", "Vewd Browser"),
("V5", "VibeMate"),
Expand Down Expand Up @@ -702,6 +735,7 @@ fn available_browsers() -> HashMap<String, String> {
("YG", "YAGI"),
("YJ", "Yahoo! Japan Browser"),
("YA", "Yandex Browser"),
("Y4", "Yandex Browser Corp"),
("YL", "Yandex Browser Lite"),
("YN", "Yaani Browser"),
("Y2", "Yo Browser"),
Expand All @@ -710,13 +744,15 @@ fn available_browsers() -> HashMap<String, String> {
("Y3", "YouBrowser"),
("YZ", "Yuzu Browser"),
("XR", "xBrowser"),
("X3", "MMBOX XBrowser"),
("XB", "X Browser Lite"),
("X0", "X-VPN"),
("X1", "xBrowser Pro Super Fast"),
("XN", "XNX Browser"),
("XT", "XtremeCast"),
("XS", "xStand"),
("XI", "Xiino"),
("X4", "XnBrowse"),
("XO", "Xooloo Internet"),
("XV", "Xvast"),
("ZE", "Zetakey"),
Expand All @@ -732,9 +768,9 @@ fn available_browsers() -> HashMap<String, String> {

fn browser_families() -> HashMap<String, Vec<String>> {
[
("Android Browser", vec!["AN", "MU"]),
("Android Browser", vec!["AN"]),
("BlackBerry Browser", vec!["BB"]),
("Baidu", vec!["BD", "BS"]),
("Baidu", vec!["BD", "BS", "H6"]),
("Amiga", vec!["AV", "AW"]),
(
"Chrome",
Expand All @@ -757,16 +793,18 @@ fn browser_families() -> HashMap<String, Vec<String>> {
"V4", "H4", "1T", "M5", "0S", "0C", "ZR", "D6", "F6", "RC", "WD", "P3", "FT", "A9",
"X2", "N3", "GD", "O9", "Q3", "F7", "K2", "P5", "H5", "V3", "K3", "Q4", "G2", "R2",
"WX", "XP", "3I", "BG", "R0", "JO", "OL", "GN", "W4", "QI", "E1", "RI", "8B", "5B",
"K4", "WK",
"K4", "WK", "T3", "K5", "MU", "9P", "K6", "VR", "N9", "M9", "F9", "0P", "0A", "JR",
"D3", "TK", "BP", "2F", "2M", "K7", "1N", "8A", "H7", "X3", "T4", "X4", "5O", "8C",
"3M", "6I", "2P", "PU", "7I", "X5", "AL",
],
),
(
"Firefox",
vec![
"FF", "BI", "BF", "BH", "BN", "C0", "CU", "EI", "F1", "FB", "FE", "AX", "FM", "FR",
"FY", "GZ", "I4", "IF", "IW", "LH", "LY", "MB", "MN", "MO", "MY", "OA", "OS", "PI",
"PX", "QA", "S5", "SX", "TF", "TO", "WF", "ZV", "FP", "AD", "WL", "2I", "P9", "KJ",
"WY", "VK", "W5", "7C", "N7", "W7", "8P",
"PX", "QA", "S5", "SX", "TF", "TO", "WF", "ZV", "FP", "AD", "2I", "P9", "KJ", "WY",
"VK", "W5", "7C", "N7", "W7", "8P",
],
),
(
Expand Down Expand Up @@ -801,19 +839,20 @@ fn browser_families() -> HashMap<String, Vec<String>> {

pub fn mobile_only_browsers() -> HashSet<String> {
[
"36", "AH", "AI", "BL", "C1", "C4", "CB", "CW", "DB", "DD", "DT", "EU", "EZ", "FK", "FM",
"36", "AH", "AI", "BL", "C1", "C4", "CB", "CW", "DB", "3M", "DT", "EU", "EZ", "FK", "FM",
"FR", "FX", "GH", "GI", "GR", "HA", "HU", "IV", "JB", "KD", "M1", "MF", "MN", "MZ", "NX",
"OC", "OI", "OM", "OZ", "PU", "PI", "PE", "QU", "RE", "S0", "S7", "SA", "SB", "SG", "SK",
"OC", "OI", "OM", "OZ", "2P", "PI", "PE", "QU", "RE", "S0", "S7", "SA", "SB", "SG", "SK",
"ST", "SU", "T1", "UH", "UM", "UT", "VE", "VV", "WI", "WP", "YN", "IO", "IS", "HQ", "RW",
"HI", "PN", "BW", "YO", "PK", "MR", "AP", "AK", "UI", "SD", "VN", "4S", "RF", "LR", "SQ",
"BV", "L1", "F0", "KS", "V0", "C8", "AZ", "MM", "BT", "N0", "P0", "F3", "DU", "D0", "P1",
"O4", "XO", "U0", "B0", "VA", "X0", "A5", "X1", "18", "B5", "B6", "TC", "A6", "2X", "F4",
"YG", "WR", "NA", "DM", "1M", "A7", "XN", "XT", "XB", "W1", "HT", "B7", "B9", "T0", "I8",
"O6", "P7", "O8", "4B", "A8", "P8", "1W", "EV", "Z0", "I9", "V4", "H4", "M5", "0S", "0C",
"ZR", "D6", "F6", "P3", "FT", "A9", "X2", "NI", "FG", "TH", "N3", "GD", "O9", "Q3", "F7",
"K2", "N4", "P5", "H5", "V3", "G2", "BG", "OL", "II", "TL", "M6", "Y3", "M7", "GN", "D3",
"K2", "N4", "P5", "H5", "V3", "G2", "BG", "OL", "II", "TL", "M6", "Y3", "M7", "GN", "JR",
"IG", "HW", "4O", "OU", "5P", "KE", "5A", "TT", "6P", "G3", "7P", "VU", "F8", "L4", "DK",
"DP", "KL", "K4", "N6", "KU", "WK", "M8", "UP", "ZT",
"DP", "KL", "K4", "N6", "KU", "WK", "M8", "UP", "ZT", "9P", "N8", "VR", "N9", "M9", "F9",
"0P", "0A", "2F", "2M", "K7", "1N", "8A", "H7", "X3", "X4", "5O", "6I", "7I", "X5",
]
.into_iter()
.map(|f| f.to_owned())
Expand Down
Loading

0 comments on commit e4d4ca3

Please sign in to comment.