Skip to main content

cortex_runtime/stealth/
fingerprint.rs

1//! Browser fingerprint patching — hide automation signals.
2
3/// JavaScript to inject that patches navigator.webdriver and chrome.runtime.
4pub const STEALTH_SCRIPT: &str = r#"
5(() => {
6    // Hide webdriver flag
7    Object.defineProperty(navigator, 'webdriver', {
8        get: () => false,
9        configurable: true,
10    });
11
12    // Patch chrome.runtime to look like a real browser
13    if (!window.chrome) {
14        window.chrome = {};
15    }
16    if (!window.chrome.runtime) {
17        window.chrome.runtime = {
18            connect: function() {},
19            sendMessage: function() {},
20        };
21    }
22
23    // Override permissions query to hide "notifications" prompt
24    const originalQuery = window.navigator.permissions.query;
25    window.navigator.permissions.query = (parameters) =>
26        parameters.name === 'notifications'
27            ? Promise.resolve({ state: Notification.permission })
28            : originalQuery(parameters);
29
30    // Patch plugins to appear non-empty
31    Object.defineProperty(navigator, 'plugins', {
32        get: () => [1, 2, 3, 4, 5],
33        configurable: true,
34    });
35
36    // Patch languages
37    Object.defineProperty(navigator, 'languages', {
38        get: () => ['en-US', 'en'],
39        configurable: true,
40    });
41})();
42"#;
43
44/// Get the stealth injection script.
45pub fn stealth_script() -> &'static str {
46    STEALTH_SCRIPT
47}