Skip to content

Commit 56ba362

Browse files
committed
chore(chrome): add gpu requestAdapter spoof
1 parent e753012 commit 56ba362

File tree

10 files changed

+32
-20
lines changed

10 files changed

+32
-20
lines changed

Cargo.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

default.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
let
44
spider = pkgs.rustPlatform.buildRustPackage {
55
pname = "spider";
6-
version = "2.36.116";
6+
version = "2.36.117";
77

88
src = ./.;
99

spider/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spider"
3-
version = "2.36.116"
3+
version = "2.36.117"
44
authors = ["j-mendez <[email protected]>"]
55
description = "A web crawler and scraper, building blocks for data curation workloads."
66
repository = "https://github.com/spider-rs/spider"

spider_chrome/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spider_chrome"
3-
version = "2.36.116"
3+
version = "2.36.117"
44
rust-version = "1.70"
55
authors = ["j-mendez <[email protected]>"]
66
edition = "2021"

spider_chrome/src/javascript/spoofs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub const PLUGIN_AND_MIMETYPE_SPOOF: &str = r#"(()=>{const m=[{type:'application
99
pub const GPU_SPOOF_SCRIPT: &str = r#"(() =>{class WGSLanguageFeatures{constructor(){this.size=4}}class GPU{constructor(){this.wgslLanguageFeatures=new WGSLanguageFeatures()}requestAdapter(){return Promise.resolve({requestDevice:()=>Promise.resolve({})})}getPreferredCanvasFormat(){return'rgba8unorm'}}const _gpu=new GPU(),_g=()=>_gpu;Object.defineProperty(_g,'toString',{value:()=>`function get gpu() { [native code] }`,configurable:true});Object.defineProperty(Navigator.prototype,'gpu',{get:_g,configurable:true,enumerable:false});if(typeof WorkerNavigator!=='undefined'){Object.defineProperty(WorkerNavigator.prototype,'gpu',{get:_g,configurable:true,enumerable:false})}})();"#;
1010
pub const GPU_SPOOF_SCRIPT_MAC: &str = r#"(() =>{class WGSLanguageFeatures{constructor(){this.size=4}}class GPU{constructor(){this.wgslLanguageFeatures=new WGSLanguageFeatures()}requestAdapter(){return Promise.resolve({requestDevice:()=>Promise.resolve({})})}getPreferredCanvasFormat(){return'bgra8unorm'}}const _gpu=new GPU(),_g=()=>_gpu;Object.defineProperty(_g,'toString',{value:()=>`function get gpu() { [native code] }`,configurable:true});Object.defineProperty(Navigator.prototype,'gpu',{get:_g,configurable:true,enumerable:false});if(typeof WorkerNavigator!=='undefined'){Object.defineProperty(WorkerNavigator.prototype,'gpu',{get:_g,configurable:true,enumerable:false})}})();"#;
1111

12+
pub const GPU_REQUEST_ADAPTER: &str = r#"(()=>{const orig=navigator.gpu.requestAdapter.bind(navigator.gpu);navigator.gpu.requestAdapter=async o=>{const adapter=await orig(o),info=adapter.info;Object.defineProperties(info,{vendor:{value:'Google Inc. (NVIDIA)',writable:false,enumerable:true,configurable:true},architecture:{value:'',writable:false,enumerable:true,configurable:true},device:{value:'',writable:false,enumerable:true,configurable:true},description:{value:'',writable:false,enumerable:true,configurable:true}});return adapter;};})();"#;
13+
pub const GPU_REQUEST_ADAPTER_MAC: &str = r#"(()=>{const orig=navigator.gpu.requestAdapter.bind(navigator.gpu);navigator.gpu.requestAdapter=async o=>{const adapter=await orig(o),info=adapter.info;Object.defineProperties(info,{vendor:{value:'apple',writable:false,enumerable:true,configurable:true},architecture:{value:'metal-3',writable:false,enumerable:true,configurable:true},device:{value:'',writable:false,enumerable:true,configurable:true},description:{value:'',writable:false,enumerable:true,configurable:true}});return adapter;};})();"#;
14+
1215
pub const HIDE_WEBDRIVER: &str = r#"Object.defineProperty(Navigator.prototype,'webdriver',{get:()=>!1,configurable:!0,enumerable:!1});"#;
1316

1417
// spoof unused atm for headless browser settings entry.

spider_chrome/src/page.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ use crate::handler::PageInner;
3636
use crate::javascript::{
3737
extract::{FULL_XML_SERIALIZER_JS, OUTER_HTML},
3838
spoofs::{
39-
DISABLE_DIALOGS, GPU_SPOOF_SCRIPT, GPU_SPOOF_SCRIPT_MAC, HIDE_CHROME, HIDE_PERMISSIONS,
40-
HIDE_WEBDRIVER, HIDE_WEBGL, HIDE_WEBGL_MAC, NAVIGATOR_SCRIPT, PLUGIN_AND_MIMETYPE_SPOOF,
39+
DISABLE_DIALOGS, GPU_REQUEST_ADAPTER, GPU_REQUEST_ADAPTER_MAC, GPU_SPOOF_SCRIPT,
40+
GPU_SPOOF_SCRIPT_MAC, HIDE_CHROME, HIDE_PERMISSIONS, HIDE_WEBDRIVER, HIDE_WEBGL,
41+
HIDE_WEBGL_MAC, NAVIGATOR_SCRIPT, PLUGIN_AND_MIMETYPE_SPOOF,
4142
},
4243
};
4344
use crate::js::{Evaluation, EvaluationResult};
@@ -79,32 +80,40 @@ pub enum AgentOs {
7980

8081
/// Generate the initial stealth script to send in one command.
8182
fn build_stealth_script(tier: Tier, os: AgentOs) -> String {
82-
let spoof_gpu = if os == AgentOs::Mac {
83+
let mac_spoof = os == AgentOs::Mac;
84+
85+
let spoof_gpu = if mac_spoof {
8386
GPU_SPOOF_SCRIPT_MAC
8487
} else {
8588
GPU_SPOOF_SCRIPT
8689
};
8790

88-
let spoof_webgl = if os == AgentOs::Mac {
91+
let spoof_webgl = if mac_spoof {
8992
HIDE_WEBGL_MAC
9093
} else {
9194
HIDE_WEBGL
9295
};
9396

97+
let spoof_gpu_adapter = if mac_spoof {
98+
GPU_REQUEST_ADAPTER_MAC
99+
} else {
100+
GPU_REQUEST_ADAPTER
101+
};
102+
94103
if tier == Tier::Basic {
95104
format!(
96-
r#"{HIDE_CHROME};{spoof_webgl};{HIDE_PERMISSIONS};{NAVIGATOR_SCRIPT};{PLUGIN_AND_MIMETYPE_SPOOF};"#
105+
r#"{HIDE_CHROME};{spoof_webgl};{spoof_gpu_adapter};{HIDE_PERMISSIONS};{NAVIGATOR_SCRIPT};{PLUGIN_AND_MIMETYPE_SPOOF};"#
97106
)
98107
} else if tier == Tier::BasicNoWebgl {
99108
format!(
100109
r#"{HIDE_CHROME};{HIDE_PERMISSIONS};{NAVIGATOR_SCRIPT};{PLUGIN_AND_MIMETYPE_SPOOF};"#
101110
)
102111
} else if tier == Tier::Mid {
103112
format!(
104-
r#"{HIDE_CHROME};{spoof_webgl};{HIDE_PERMISSIONS};{HIDE_WEBDRIVER};{NAVIGATOR_SCRIPT};{PLUGIN_AND_MIMETYPE_SPOOF};"#
113+
r#"{HIDE_CHROME};{spoof_webgl};{spoof_gpu_adapter};{HIDE_PERMISSIONS};{HIDE_WEBDRIVER};{NAVIGATOR_SCRIPT};{PLUGIN_AND_MIMETYPE_SPOOF};"#
105114
)
106115
} else if tier == Tier::Full {
107-
format!("{HIDE_CHROME};{spoof_webgl};{HIDE_PERMISSIONS};{HIDE_WEBDRIVER};{NAVIGATOR_SCRIPT};{PLUGIN_AND_MIMETYPE_SPOOF};{spoof_gpu};")
116+
format!("{HIDE_CHROME};{spoof_webgl};{spoof_gpu_adapter};{HIDE_PERMISSIONS};{HIDE_WEBDRIVER};{NAVIGATOR_SCRIPT};{PLUGIN_AND_MIMETYPE_SPOOF};{spoof_gpu};")
108117
} else {
109118
Default::default()
110119
}

spider_cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spider_cli"
3-
version = "2.36.116"
3+
version = "2.36.117"
44
authors = ["j-mendez <[email protected]>"]
55
description = "The fastest web crawler CLI written in Rust."
66
repository = "https://github.com/spider-rs/spider"

spider_transformations/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spider_transformations"
3-
version = "2.36.116"
3+
version = "2.36.117"
44
authors = ["j-mendez <[email protected]>"]
55
description = "Transformation utils to use for Spider Web Crawler."
66
repository = "https://github.com/spider-rs/spider-transformations"

spider_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spider_utils"
3-
version = "2.36.116"
3+
version = "2.36.117"
44
authors = ["j-mendez <[email protected]>"]
55
description = "Utilities to use for Spider Web Crawler."
66
repository = "https://github.com/spider-rs/spider"

spider_worker/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spider_worker"
3-
version = "2.36.116"
3+
version = "2.36.117"
44
authors = ["j-mendez <[email protected]>"]
55
description = "The fastest web crawler as a worker or proxy."
66
repository = "https://github.com/spider-rs/spider"

0 commit comments

Comments
 (0)