| 1 | package Firefox::Marionette::Extension::Stealthscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/; |
| 2 | |
| 3 | use File::HomeDirscip-perl cpan Firefox-Marionette 1.70 File/HomeDir/(); |
| 4 | use File::Specscip-perl cpan Firefox-Marionette 1.70 File/Spec/(); |
| 5 | use Archive::Zipscip-perl cpan Firefox-Marionette 1.70 Archive/Zip/(); |
| 6 | use Englishscip-perl cpan Firefox-Marionette 1.70 English/ qw( -no_match_vars ); |
| 7 | use strictscip-perl cpan Firefox-Marionette 1.70 strict/; |
| 8 | use warningsscip-perl cpan Firefox-Marionette 1.70 warnings/; |
| 9 | |
| 10 | our $VERSIONscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$VERSION. = '1.70'; |
| 11 | |
| 12 | sub _BUFFER_SIZEscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_BUFFER_SIZE(). { return 65_536 } |
| 13 | sub _MSIE_VERSIONscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_MSIE_VERSION(). { return 11 } |
| 14 | |
| 15 | my $content_name = 'content.js'; |
| 16 | |
| 17 | my %_function_bodies = ( |
| 18 | 'Navigator.bluetooth' => |
| 19 | q[return { getAvailability: function () { return new Promise((resolve, reject) => resolve(false))} };], |
| 20 | 'Navigator.canShare' => q[return true], |
| 21 | 'Navigator.clearAppBadge' => |
| 22 | q[return new Promise((resolve, reject) => resolve(undefined))], |
| 23 | 'Navigator.connection' => |
| 24 | q[let downlink = (new Array(7.55, 1.6))[Math.floor(Math.random() * 2)]; let rtt = (new Array(50, 100))[Math.floor(Math.random() * 2)]; let obj = { onchange: null, effectiveType: decodeURIComponent(\\x27%274g%27\\x27), rtt: rtt, downlink: downlink, saveData: false }; return new NetworkInformation(obj)], |
| 25 | 'Navigator.deprecatedReplaceInURN' => |
| 26 | q[throw TypeError(decodeURIComponent(\\x27Failed to execute %27deprecatedReplaceInURN%27 on %27Navigator%27: Passed URL must be a valid URN URL.\\x27))], |
| 27 | 'Navigator.deprecatedURNtoURL' => |
| 28 | q[throw TypeError(decodeURIComponent(\\x27Failed to execute %27deprecatedURNtoURL%27 on %27Navigator%27: Passed URL must be a valid URN URL.\\x27))], |
| 29 | 'Navigator.deviceMemory' => |
| 30 | q[return (navigator.hardwareConcurrency < 4 ? 4 : 8)], |
| 31 | 'Navigator.getBattery' => |
| 32 | q[return new Promise((resolve, reject) => resolve({ charging: true, chargingTime: 0, dischargingTime: Infinity, level: 1, onchargingchange: null }))], |
| 33 | 'Navigator.getGamePads' => q[return new Array( null, null, null, null )], |
| 34 | 'Navigator.getInstalledRelatedApps' => |
| 35 | q[return new Promise((resolve,reject) => resolve([]))], |
| 36 | 'Navigator.getUserMedia' => q[return getUserMedia], |
| 37 | 'Navigator.gpu' => q[return { wgslLanguageFeatures: { size: 0 } }], |
| 38 | 'Navigator.hid' => |
| 39 | q[return { getDevices: function() { return new Promise((resolve,reject) => resolve([])) }, requestDevices: function() { return new Promise((resolve, reject) => resolve([])) } }], |
| 40 | 'Navigator.ink' => q[return {}], |
| 41 | 'Navigator.keyboard' => |
| 42 | q[return { getLayoutMap: function() { }, lock: function() { }, unlock: function() { } }], |
| 43 | 'Navigator.locks' => |
| 44 | q[return { query: function() { }, request: function() { } }], |
| 45 | 'Navigator.login' => |
| 46 | q[return { setStatus: function() { return undefined } }], |
| 47 | 'Navigator.webkitGetUserMedia' => q[return getUserMedia], |
| 48 | 'Navigator.xr' => q[return new XRSystem({ondevicechange: null})], |
| 49 | ); |
| 50 | |
| 51 | sub newscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/new(). { |
| 52 | my ( $class, %agent_parameters ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 53 | my $zip = Archive::Zip->newscip-perl cpan Firefox-Marionette 1.70 Archive/Zip/new().(); |
| 54 | my $manifest = |
| 55 | $zip->addStringscip-perl cpan Firefox-Marionette 1.70 Archive/Zip/addString().( $class->_manifest_contentsscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_manifest_contents().(), 'manifest.json' ); |
| 56 | $manifest->desiredCompressionMethodscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/desiredCompressionMethod().( Archive::Zip::COMPRESSION_DEFLATEDscip-perl cpan Firefox-Marionette 1.70 Archive/Zip/COMPRESSION_DEFLATED().() ); |
| 57 | my $content = $zip->addStringscip-perl cpan Firefox-Marionette 1.70 Archive/Zip/addString().( $class->_content_contentsscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_content_contents().(%agent_parameters), |
| 58 | $content_name ); |
| 59 | $content->desiredCompressionMethodscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/desiredCompressionMethod().( Archive::Zip::COMPRESSION_DEFLATEDscip-perl cpan Firefox-Marionette 1.70 Archive/Zip/COMPRESSION_DEFLATED().() ); |
| 60 | return $zip; |
| 61 | } |
| 62 | |
| 63 | sub _manifest_contentsscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_manifest_contents(). { |
| 64 | my ($class) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 65 | return <<"_JS_"; |
| 66 | { |
| 67 | "description": "Firefox::Marionette Stealth extension", |
| 68 | "manifest_version": 2, |
| 69 | "name": "Firefox Marionette Stealth extension", |
| 70 | "version": "1.1", |
| 71 | "permissions": [ |
| 72 | "activeTab" |
| 73 | ], |
| 74 | "content_scripts": [ |
| 75 | { |
| 76 | "matches": ["<all_urls>"], |
| 77 | "js": ["$content_name"], |
| 78 | "match_about_blank": true, |
| 79 | "run_at": "document_start", |
| 80 | "all_frames": true |
| 81 | } |
| 82 | ] |
| 83 | } |
| 84 | _JS_ |
| 85 | } |
| 86 | |
| 87 | sub _content_contentsscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_content_contents(). { |
| 88 | my ( $class, %agent_parameters ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 89 | my $user_agent_contents = $class->user_agent_contentsscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/user_agent_contents().(%agent_parameters); |
| 90 | $user_agent_contents =~ s/\s+/ /smxg; |
| 91 | $user_agent_contents =~ s/\\n/\\\\n/smxg; |
| 92 | return <<"_JS_"; |
| 93 | { |
| 94 | let script = document.createElement('script'); |
| 95 | let text = document.createTextNode('$user_agent_contents'); |
| 96 | script.appendChild(text); |
| 97 | (document.head || document.documentElement).appendChild(script); |
| 98 | script.remove(); |
| 99 | } |
| 100 | _JS_ |
| 101 | } |
| 102 | |
| 103 | my $_function_definition_count = 1; |
| 104 | |
| 105 | sub _get_browser_type_and_versionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_get_browser_type_and_version(). { |
| 106 | my ( $class, $user_agent_string ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 107 | my ( $browser_type, $browser_version ); |
| 108 | if ( $user_agent_string =~ /Chrome\/(\d+)/smx ) { |
| 109 | ( $browser_type, $browser_version ) = ( 'chrome', $1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1. ); |
| 110 | if ( $user_agent_string =~ /Edg(?:[eA]|iOS)?\/(\d+)/smx ) { |
| 111 | ( $browser_type, $browser_version ) = ( 'edge', $1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1. ); |
| 112 | } |
| 113 | elsif ( $user_agent_string =~ /(?:Opera|Presto|OPR)\/(\d+)/smx ) { |
| 114 | ( $browser_type, $browser_version ) = ( 'opera', $1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1. ); |
| 115 | } |
| 116 | } |
| 117 | elsif ( |
| 118 | $user_agent_string =~ /Version\/(\d+)(?:[.]\d+)?[ ].*Safari\/\d+/smx ) |
| 119 | { |
| 120 | ( $browser_type, $browser_version ) = ( 'safari', $1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1. ); |
| 121 | } |
| 122 | elsif ( $user_agent_string =~ /Trident/smx ) { |
| 123 | ( $browser_type, $browser_version ) = ( 'ie', _MSIE_VERSIONscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_MSIE_VERSION().() ); |
| 124 | } |
| 125 | my $general_token_re = qr/Mozilla\/5[.]0[ ]/smx; |
| 126 | my $platform_etc_re = qr/[(][^)]+[)][ ]/smx; |
| 127 | my $gecko_trail_re = qr/Gecko\/20100101[ ]/smx; |
| 128 | my $firefox_version_re = qr/Firefox\/(\d+)[.]0/smx; |
| 129 | if ( $user_agent_string =~ |
| 130 | /^$general_token_re$platform_etc_re$gecko_trail_re$firefox_version_re$/smx |
| 131 | ) |
| 132 | { |
| 133 | ( $browser_type, $browser_version ) = ( 'firefox', $1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1. ); |
| 134 | } |
| 135 | return ( $browser_type, $browser_version ); |
| 136 | } |
| 137 | |
| 138 | sub user_agent_contentsscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/user_agent_contents(). { |
| 139 | my ( $class, %parameters ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 140 | my ( $to_browser_type, $to_browser_version ); |
| 141 | if ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $parameters{to} ) { |
| 142 | ( $to_browser_type, $to_browser_version ) = |
| 143 | $class->_get_browser_type_and_versionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_get_browser_type_and_version().( $parameters{to} ); |
| 144 | } |
| 145 | $_function_definition_count = 1; |
| 146 | my ( $definition_name, $function_definition ) = |
| 147 | $class->_get_js_function_definitionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_get_js_function_definition().( $to_browser_type, 'Navigator', |
| 148 | 'webdriver', 'return false' ); |
| 149 | my $native_code_body = $class->_native_code_bodyscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_native_code_body().($to_browser_type); |
| 150 | my $contents = <<"_JS_"; |
| 151 | { |
| 152 | if (("console" in window) && ("log" in window.console)) { |
| 153 | console.log("Loading Firefox::Marionette::Extension::Stealth"); |
| 154 | } |
| 155 | let navProto = Object.getPrototypeOf(window.navigator); |
| 156 | let winProto = Object.getPrototypeOf(window); |
| 157 | $function_definition |
| 158 | Object.defineProperty(navProto, "webdriver", {get: $definition_name, enumerable: false, configurable: true}); |
| 159 | console.clear = function() { console.log("$class blocked an attempt at clearing the console...") }; |
| 160 | console.clear.toString = function clear_def() { return "function clear() $native_code_body" }; |
| 161 | let getUserMedia = navProto.mozGetUserMedia; |
| 162 | _JS_ |
| 163 | my ( $from_browser_type, $from_browser_version ); |
| 164 | if ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $to_browser_type ) { |
| 165 | ( $from_browser_type, $from_browser_version ) = |
| 166 | $class->_get_browser_type_and_versionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_get_browser_type_and_version().( $parameters{from} ); |
| 167 | if ( ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $from_browser_type ) |
| 168 | && ( $from_browser_type ne $to_browser_type ) ) |
| 169 | { |
| 170 | $contents .= <<"_JS_"; |
| 171 | window.eval.toString = function eval_def() { return "function eval() $native_code_body" }; |
| 172 | Function.prototype.bind.toString = function bind_def() { return "function bind() $native_code_body" }; |
| 173 | _JS_ |
| 174 | } |
| 175 | if ( ( $to_browser_type eq 'chrome' ) |
| 176 | || ( $to_browser_type eq 'edge' ) |
| 177 | || ( $to_browser_type eq 'opera' ) ) |
| 178 | { |
| 179 | $contents .= $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( |
| 180 | $to_browser_type, |
| 181 | 'Navigator.webkitPersistentStorage', |
| 182 | { |
| 183 | function_body => |
| 184 | q[return { queryUsageAndQuota: function() { return undefined }, requestQuota: function() { return undefined } }] |
| 185 | }, |
| 186 | {} |
| 187 | ); |
| 188 | $contents .= $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( |
| 189 | $to_browser_type, |
| 190 | 'Navigator.webkitTemporaryStorage', |
| 191 | { |
| 192 | function_body => |
| 193 | q[return { queryUsageAndQuota: function() { return undefined }, requestQuota: function() { return undefined } }] |
| 194 | }, |
| 195 | {} |
| 196 | ); |
| 197 | $contents .= $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( |
| 198 | $to_browser_type, |
| 199 | 'Window.webkitResolveLocalFileSystemURL', |
| 200 | { function_body => q[return undefined] }, {} |
| 201 | ); |
| 202 | $contents .= |
| 203 | $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( $to_browser_type, |
| 204 | 'Window.webkitMediaStream', |
| 205 | { function_body => q[return undefined] }, {} ); |
| 206 | $contents .= |
| 207 | $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( $to_browser_type, |
| 208 | 'Window.webkitSpeechGrammar', |
| 209 | { function_body => q[return undefined] }, {} ); |
| 210 | $contents .= <<'_JS_'; |
| 211 | delete navProto.oscpu; |
| 212 | delete window.ApplePayError; |
| 213 | delete window.CSSPrimitiveValue; |
| 214 | delete window.Counter; |
| 215 | delete navigator.getStorageUpdates; |
| 216 | delete window.WebKitMediaKeys; |
| 217 | let chrome = { |
| 218 | csi: function () { }, |
| 219 | getVariableName: function () { }, |
| 220 | loadTimes: function () { }, |
| 221 | metricsPrivate: { |
| 222 | MetricTypeType: { |
| 223 | HISTOGRAM_LINEAR: "histogram-linear", |
| 224 | HISTOGRAM_LOG: "histogram-log" |
| 225 | }, |
| 226 | getFieldTrial: function () { }, |
| 227 | getHistogram: function () { }, |
| 228 | getVariationParams: function () { }, |
| 229 | recordBoolean: function () { }, |
| 230 | recordCount: function () { }, |
| 231 | recordEnumerationValue: function () { }, |
| 232 | recordLongTime: function () { }, |
| 233 | recordMediumCount: function () { }, |
| 234 | recordMediumTime: function () { }, |
| 235 | recordPercentage: function () { }, |
| 236 | recordSmallCount: function () { }, |
| 237 | recordSparseValue: function () { }, |
| 238 | recordSparseValueWithHashMetricName: function () { }, |
| 239 | recordSparseValueWithPersistentHash: function () { }, |
| 240 | recordTime: function () { }, |
| 241 | recordUserAction: function () { }, |
| 242 | recordValue: function () { } |
| 243 | }, |
| 244 | send: function () { }, |
| 245 | timeTicks: { nowInMicroseconds: function () { } }, |
| 246 | webstore: function () { }, |
| 247 | app: function () { }, |
| 248 | runtime: { connect: function() { }, sendMessage: function() { } } |
| 249 | }; |
| 250 | Object.defineProperty(winProto, "chrome", {value: chrome, writable: true, enumerable: true, configurable: true}); |
| 251 | |
| 252 | let canLoadAdAuctionFencedFrame = function() { return true }; |
| 253 | |
| 254 | Object.defineProperty(navProto, "canLoadAdAuctionFencedFrame", {value: canLoadAdAuctionFencedFrame, writable: true, enumerable: true, configurable: true}); |
| 255 | |
| 256 | let createAuctionNonce = function() { return crypto.randomUUID() }; |
| 257 | Object.defineProperty(navProto, "createAuctionNonce", {value: createAuctionNonce, writable: true, enumerable: true, configurable: true}); |
| 258 | |
| 259 | Object.defineProperty(navProto, "deprecatedRunAdAuctionEnforcesKAnonymity", {value: false, writable: true, enumerable: true, configurable: true}); |
| 260 | _JS_ |
| 261 | |
| 262 | if ( $to_browser_type eq 'edge' ) { |
| 263 | } |
| 264 | elsif ( $to_browser_type eq 'opera' ) { |
| 265 | my ( $scrap_name, $scrap_definition ) = |
| 266 | $class->_get_js_function_definitionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_get_js_function_definition().( $to_browser_type, |
| 267 | 'Window', 'scrap', 'return null' ); |
| 268 | $contents .= <<"_JS_"; |
| 269 | $scrap_definition |
| 270 | Object.defineProperty(winProto, "g_opr", {value: {scrap: $scrap_name}, enumerable: true, configurable: true}); |
| 271 | Object.defineProperty(winProto, "opr", {value: {}, enumerable: true, configurable: true}); |
| 272 | _JS_ |
| 273 | } |
| 274 | } |
| 275 | elsif ( $to_browser_type eq 'safari' ) { |
| 276 | $contents .= <<'_JS_'; |
| 277 | delete navProto.oscpu; |
| 278 | delete navigator.webkitPersistentStorage; |
| 279 | delete navigator.webkitTemporaryStorage; |
| 280 | delete window.webkitResolveLocalFileSystemURL; |
| 281 | delete window.webkitMediaStream; |
| 282 | delete window.webkitSpeechGrammar; |
| 283 | _JS_ |
| 284 | $contents .= |
| 285 | $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( $to_browser_type, |
| 286 | 'Window.ApplePayError', |
| 287 | { function_body => q[return undefined] }, {} ); |
| 288 | $contents .= |
| 289 | $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( $to_browser_type, |
| 290 | 'Window.CSSPrimitiveValue', |
| 291 | { function_body => q[return undefined] }, {} ); |
| 292 | $contents .= |
| 293 | $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( $to_browser_type, |
| 294 | 'Window.Counter', { function_body => q[return undefined] }, |
| 295 | {} ); |
| 296 | $contents .= |
| 297 | $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( $to_browser_type, |
| 298 | 'Navigator.getStorageUpdates', |
| 299 | { function_body => q[return undefined] }, {} ); |
| 300 | $contents .= |
| 301 | $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( $to_browser_type, |
| 302 | 'Window.WebKitMediaKeys', |
| 303 | { function_body => q[return undefined] }, {} ); |
| 304 | } |
| 305 | elsif ( $to_browser_type eq 'ie' ) { |
| 306 | $contents .= <<'_JS_'; |
| 307 | let docProto = Object.getPrototypeOf(window.document); |
| 308 | delete navigator.webkitPersistentStorage; |
| 309 | delete navigator.webkitTemporaryStorage; |
| 310 | delete window.webkitResolveLocalFileSystemURL; |
| 311 | delete window.webkitMediaStream; |
| 312 | delete window.webkitSpeechGrammar; |
| 313 | delete window.ApplePayError; |
| 314 | delete window.CSSPrimitiveValue; |
| 315 | delete window.Counter; |
| 316 | delete navigator.getStorageUpdates; |
| 317 | delete window.WebKitMediaKeys; |
| 318 | Object.defineProperty(docProto, "documentMode", {value: true, writable: true, enumerable: true, configurable: true}); |
| 319 | Object.defineProperty(navProto, "msDoNotTrack", {value: "0", writable: true, configurable: true}); |
| 320 | Object.defineProperty(winProto, "msWriteProfilerMark", {value: {}, writable: true, configurable: true}); |
| 321 | _JS_ |
| 322 | } |
| 323 | if ( $to_browser_type eq 'firefox' ) { |
| 324 | $contents .= <<'_JS_'; |
| 325 | delete navigator.webkitPersistentStorage; |
| 326 | delete navigator.webkitTemporaryStorage; |
| 327 | delete window.webkitResolveLocalFileSystemURL; |
| 328 | delete window.webkitMediaStream; |
| 329 | delete window.webkitSpeechGrammar; |
| 330 | delete window.ApplePayError; |
| 331 | delete window.CSSPrimitiveValue; |
| 332 | delete window.Counter; |
| 333 | delete navigator.getStorageUpdates; |
| 334 | delete window.WebKitMediaKeys; |
| 335 | if ("onmozfullscreenchange" in window) { |
| 336 | } else { |
| 337 | Object.defineProperty(window, "onmozfullscreenchange", {value: undefined, writable: true, configurable: true}); |
| 338 | } |
| 339 | if ("mozInnerScreenX" in window) { |
| 340 | } else { |
| 341 | Object.defineProperty(window, "mozInnerScreenX", {value: 0, writable: true, configurable: true}); |
| 342 | } |
| 343 | if ("CSSMozDocumentRule" in window) { |
| 344 | } else { |
| 345 | Object.defineProperty(window, "CSSMozDocumentRule", {value: undefined, writable: true, configurable: true}); |
| 346 | } |
| 347 | if ("CanvasCaptureMediaStream" in window) { |
| 348 | } else { |
| 349 | Object.defineProperty(window, "CanvasCaptureMediaStream", {value: undefined, writable: true, configurable: true}); |
| 350 | } |
| 351 | _JS_ |
| 352 | } |
| 353 | else { |
| 354 | $contents .= <<'_JS_'; |
| 355 | delete navProto.buildID; |
| 356 | delete window.InstallTrigger; |
| 357 | delete navProto.mozGetUserMedia; |
| 358 | delete window.onmozfullscreenchange; |
| 359 | delete window.mozInnerScreenX; |
| 360 | delete window.CSSMozDocumentRule; |
| 361 | delete window.CanvasCaptureMediaStream; |
| 362 | _JS_ |
| 363 | } |
| 364 | if ($from_browser_version) { |
| 365 | $contents .= $class->_browser_compat_datascip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_browser_compat_data().( |
| 366 | from_browser_type => $from_browser_type, |
| 367 | from_browser_version => $from_browser_version, |
| 368 | to_browser_type => $to_browser_type, |
| 369 | to_browser_version => $to_browser_version, |
| 370 | filters => $parameters{filters}, |
| 371 | ); |
| 372 | } |
| 373 | } |
| 374 | my %navigator_agent_mappings = ( |
| 375 | to => 'userAgent', |
| 376 | app_version => 'appVersion', |
| 377 | platform => 'platform', |
| 378 | product => 'product', |
| 379 | product_sub => 'productSub', |
| 380 | vendor => 'vendor', |
| 381 | vendor_sub => 'vendorSub', |
| 382 | oscpu => 'oscpu', |
| 383 | ); |
| 384 | foreach my $key ( sortscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/sort(). { $ascip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$a. cmp $bscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$b. } keysscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/keys(). %navigator_agent_mappings ) { |
| 385 | if ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $parameters{$key} ) { |
| 386 | my $encoded = URI::Escape::uri_escapescip-perl cpan Firefox-Marionette 1.70 URI/Escape/uri_escape().( $parameters{$key} ); |
| 387 | $contents .= $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( |
| 388 | $to_browser_type, |
| 389 | 'Navigator.' . $navigator_agent_mappings{$key}, |
| 390 | { |
| 391 | function_body => |
| 392 | qq[return decodeURIComponent(\\x27$encoded\\x27)], |
| 393 | override => 1 |
| 394 | }, |
| 395 | {} |
| 396 | ); |
| 397 | } |
| 398 | elsif ( $parameters{to} ) { |
| 399 | $contents .= <<"_JS_"; |
| 400 | delete navigator.$navigator_agent_mappings{$key}; |
| 401 | _JS_ |
| 402 | } |
| 403 | } |
| 404 | $contents .= <<'_JS_'; |
| 405 | if (("console" in window) && ("log" in window.console)) { |
| 406 | console.log("Loaded Firefox::Marionette::Extension::Stealth"); |
| 407 | } |
| 408 | } |
| 409 | _JS_ |
| 410 | return $contents; |
| 411 | } |
| 412 | |
| 413 | sub _check_and_add_classscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_class(). { |
| 414 | my ( $class, $property_name, $to_string_tag_allowed ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 415 | my $javascript_class = $property_name; |
| 416 | my $win_proto_class = $javascript_class; |
| 417 | $win_proto_class =~ s/^Window[.]/winProto./smx; |
| 418 | |
| 419 | my $contents = <<"_JS_"; |
| 420 | if ("$javascript_class" in window) { |
| 421 | } else { |
| 422 | window.$javascript_class = class { |
| 423 | constructor(obj) { |
| 424 | for(let key of Object.keys(obj)) { |
| 425 | Object.defineProperty(this, key, {value: obj[key], enumerable: true, configurable: true}); |
| 426 | } |
| 427 | } |
| 428 | _JS_ |
| 429 | if ($to_string_tag_allowed) { |
| 430 | $contents .= <<"_JS_"; |
| 431 | get [Symbol.toStringTag]() { |
| 432 | return "$javascript_class"; |
| 433 | } |
| 434 | _JS_ |
| 435 | } |
| 436 | $contents .= <<"_JS_"; |
| 437 | }; |
| 438 | } |
| 439 | _JS_ |
| 440 | return $contents; |
| 441 | } |
| 442 | |
| 443 | sub _native_code_bodyscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_native_code_body(). { |
| 444 | my ( $class, $to_browser_type ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 445 | my $native_code_body = |
| 446 | q[{] . q[\\] . 'n\\x20\\x20\\x20\\x20[native code]' . q[\\] . q[n}]; |
| 447 | if ( ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $to_browser_type ) && ( $to_browser_type eq 'chrome' ) ) { |
| 448 | $native_code_body = q[{ [native code] }]; |
| 449 | } |
| 450 | return $native_code_body; |
| 451 | } |
| 452 | |
| 453 | sub _get_js_function_definitionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_get_js_function_definition(). { |
| 454 | my ( $class, $to_browser_type, $javascript_class, $name, $function_body ) = |
| 455 | @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 456 | $function_body = <<"_JS_"; |
| 457 | if ($javascript_class.prototype.isPrototypeOf(this)) { |
| 458 | $function_body |
| 459 | } else { |
| 460 | throw TypeError(decodeURIComponent(\\x27%27get $name%27 called on an object that does not implement interface $javascript_class.\\x27)); |
| 461 | } |
| 462 | _JS_ |
| 463 | $_function_definition_count += 1; |
| 464 | my $native_code_body = $class->_native_code_bodyscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_native_code_body().($to_browser_type); |
| 465 | my $actual_name = "fm_def_$_function_definition_count"; |
| 466 | return ( $actual_name, <<"_JS_" ); |
| 467 | let $actual_name = new Function("$function_body"); |
| 468 | $actual_name.toString = function fm_def() { return "function ${name}() $native_code_body" }; |
| 469 | _JS_ |
| 470 | } |
| 471 | |
| 472 | sub _check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function(). { |
| 473 | my ( $class, $to_browser_type, $property_name, $proposed_change_properties, |
| 474 | $deleted_classes ) |
| 475 | = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 476 | my $javascript_class = $property_name; |
| 477 | $javascript_class =~ s/[.][\-_@[:alnum:]]+$//smx; |
| 478 | my $function_name = $property_name; |
| 479 | $function_name =~ s/^.*[.]([\-_@[:alnum:]]+)$/$1/smx; |
| 480 | my $parent_class = $javascript_class; |
| 481 | if ( $javascript_class =~ /^(.*?)[.]/smx ) { |
| 482 | $parent_class = ($1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1.); |
| 483 | } |
| 484 | my $contents = q[]; |
| 485 | if ( !$deleted_classes->{$javascript_class} ) { |
| 486 | my ( $definition_name, $function_definition ) = |
| 487 | $class->_get_js_function_definitionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_get_js_function_definition().( $to_browser_type, |
| 488 | $javascript_class, $function_name, |
| 489 | $proposed_change_properties->{function_body} ); |
| 490 | $contents .= <<"_JS_"; |
| 491 | $function_definition |
| 492 | _JS_ |
| 493 | if ( $proposed_change_properties->{override} ) { |
| 494 | $contents .= |
| 495 | <<"_JS_"; # So far, all overrides are Navigator overrides |
| 496 | Object.defineProperty(window.$javascript_class, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 497 | Object.defineProperty(navProto, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 498 | _JS_ |
| 499 | } |
| 500 | elsif ( $javascript_class eq 'Window' ) { |
| 501 | $contents .= <<"_JS_"; |
| 502 | if ("$function_name" in window) { |
| 503 | } else { |
| 504 | Object.defineProperty(window, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 505 | } |
| 506 | _JS_ |
| 507 | } |
| 508 | else { |
| 509 | $contents .= <<"_JS_"; |
| 510 | if (winProto.$parent_class && winProto.$javascript_class) { |
| 511 | if ("$function_name" in winProto.$javascript_class) { |
| 512 | } else { |
| 513 | Object.defineProperty(winProto.$javascript_class.prototype, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 514 | } |
| 515 | } else if (window.$parent_class && window.$javascript_class) { |
| 516 | if (window.$javascript_class.prototype) { |
| 517 | if ("$function_name" in window.$javascript_class.prototype) { |
| 518 | } else { |
| 519 | Object.defineProperty(window.$javascript_class.prototype, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 520 | } |
| 521 | } else { |
| 522 | if ("$function_name" in window.$javascript_class) { |
| 523 | } else { |
| 524 | Object.defineProperty(window.$javascript_class, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 525 | } |
| 526 | } |
| 527 | _JS_ |
| 528 | if ( $javascript_class eq 'Navigator' ) { |
| 529 | $contents .= <<"_JS_"; |
| 530 | Object.defineProperty(navProto, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 531 | _JS_ |
| 532 | } |
| 533 | elsif ( $javascript_class eq 'Document' ) { |
| 534 | $contents .= <<"_JS_"; |
| 535 | Object.defineProperty(window.document, "$function_name", {get: $definition_name, enumerable: true, configurable: true}); |
| 536 | _JS_ |
| 537 | } |
| 538 | $contents .= <<"_JS_"; |
| 539 | } |
| 540 | _JS_ |
| 541 | } |
| 542 | } |
| 543 | return $contents; |
| 544 | } |
| 545 | |
| 546 | sub _check_and_delete_classscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_delete_class(). { |
| 547 | my ( $class, $property_name ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 548 | my $parent_class = $property_name; |
| 549 | if ( $property_name =~ /^(.*?)[.]/smx ) { |
| 550 | ($parent_class) = ($1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1.); |
| 551 | } |
| 552 | my $contents = <<"_JS_"; |
| 553 | if (winProto.$parent_class && winProto.$property_name) { |
| 554 | delete winProto.$property_name; |
| 555 | } else if (window.$parent_class && window.$property_name) { |
| 556 | delete window.$property_name; |
| 557 | } |
| 558 | _JS_ |
| 559 | if ( $property_name eq 'SubtleCrypto' ) { |
| 560 | $contents .= <<'_JS_'; |
| 561 | if ("crypto" in window) { |
| 562 | delete window["crypto"]; |
| 563 | } |
| 564 | _JS_ |
| 565 | } |
| 566 | else { |
| 567 | my $lc_property_name = lcscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/lc(). $property_name; |
| 568 | $contents .= <<"_JS_"; |
| 569 | if ("$lc_property_name" in window) { |
| 570 | delete window["$lc_property_name"]; |
| 571 | } |
| 572 | _JS_ |
| 573 | } |
| 574 | return $contents; |
| 575 | } |
| 576 | |
| 577 | sub _check_and_delete_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_delete_function(). { |
| 578 | my ( $class, $property_name, $deleted_classes ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 579 | my $contents = q[]; |
| 580 | my $javascript_class = $property_name; |
| 581 | $javascript_class =~ s/[.][\-_@[:alpha:]]+$//smx; |
| 582 | my $function_name = $property_name; |
| 583 | $function_name =~ s/^.*[.]([\-_@[:alpha:]]+)$/$1/smx; |
| 584 | my $parent_class = $javascript_class; |
| 585 | if ( $javascript_class =~ /^(.*?)[.]/smx ) { |
| 586 | $parent_class = ($1scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$1.); |
| 587 | } |
| 588 | if ( !$deleted_classes->{$javascript_class} ) { |
| 589 | $contents .= <<"_JS_"; |
| 590 | if (winProto.$parent_class && winProto.$javascript_class) { |
| 591 | delete winProto.$javascript_class\["$function_name"\]; |
| 592 | } else if (window.$parent_class && window.$javascript_class) { |
| 593 | if (window.$javascript_class.prototype) { |
| 594 | delete window.$javascript_class.prototype\["$function_name"\]; |
| 595 | } |
| 596 | delete window.$javascript_class\["$function_name"\]; |
| 597 | } |
| 598 | _JS_ |
| 599 | } |
| 600 | if ( $javascript_class eq 'Navigator' ) { |
| 601 | $contents .= <<"_JS_"; |
| 602 | if ("$function_name" in navProto) { |
| 603 | delete navProto["$function_name"]; |
| 604 | } else if ("$function_name" in navigator) { |
| 605 | delete navigator["$function_name"]; |
| 606 | } |
| 607 | _JS_ |
| 608 | } |
| 609 | elsif ( $javascript_class eq 'Document' ) { |
| 610 | $contents .= <<"_JS_"; |
| 611 | if (("document" in winProto) && ("$function_name" in winProto.document)) { |
| 612 | delete winProto.document["$function_name"]; |
| 613 | } else if (("document" in window) && ("$function_name" in window.document)) { |
| 614 | delete window.document["$function_name"]; |
| 615 | } |
| 616 | _JS_ |
| 617 | } |
| 618 | elsif ( $javascript_class eq 'Window' ) { |
| 619 | $contents .= <<"_JS_"; |
| 620 | if ("$function_name" in winProto) { |
| 621 | delete winProto["$function_name"]; |
| 622 | } else if ("$function_name" in window) { |
| 623 | delete window["$function_name"]; |
| 624 | } |
| 625 | _JS_ |
| 626 | } |
| 627 | return $contents; |
| 628 | } |
| 629 | |
| 630 | sub _read_bcdscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_read_bcd(). { |
| 631 | my ($class) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 632 | my %browser_properties; |
| 633 | my $bcd_path = Firefox::Marionette::BCD_PATHscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/BCD_PATH().(); |
| 634 | if ( ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $bcd_path ) |
| 635 | && ( my $bcd_handle = FileHandle->newscip-perl cpan Firefox-Marionette 1.70 FileHandle/new().( $bcd_path, Fcntl::O_RDONLYscip-perl cpan Firefox-Marionette 1.70 Fcntl/O_RDONLY().() ) ) |
| 636 | ) |
| 637 | { |
| 638 | my $bcd_contents; |
| 639 | my $result; |
| 640 | while ( $result = $bcd_handle->readscip-perl cpan Firefox-Marionette 1.70 FileHandle/read().( my $buffer, _BUFFER_SIZEscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_BUFFER_SIZE().() ) ) { |
| 641 | $bcd_contents .= $buffer; |
| 642 | } |
| 643 | closescip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/close(). $bcd_handle |
| 644 | or Firefox::Marionette::Exception->throwscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Exception/throw().( |
| 645 | "Failed to close '$bcd_path':$EXTENDED_OS_ERROR"); |
| 646 | %browser_properties = %{ JSON->newscip-perl cpan Firefox-Marionette 1.70 JSON/new().()->decodescip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/decode().($bcd_contents) }; |
| 647 | } |
| 648 | elsif ( $OS_ERRORscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$OS_ERROR. == POSIX::ENOENTscip-perl cpan Firefox-Marionette 1.70 POSIX/ENOENT().() ) { |
| 649 | Carp::carpscip-perl cpan Firefox-Marionette 1.70 Carp/carp().( |
| 650 | q[BCD file is not available. Please run 'build-bcd-for-firefox']); |
| 651 | } |
| 652 | else { |
| 653 | Firefox::Marionette::Exception->throwscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Exception/throw().( |
| 654 | "Failed to open '$bcd_path' for reading:$EXTENDED_OS_ERROR"); |
| 655 | } |
| 656 | return %browser_properties; |
| 657 | } |
| 658 | |
| 659 | sub _available_inscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_available_in(). { |
| 660 | my ( $class, %properties ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 661 | my $available; |
| 662 | my $browser_type = $properties{browser_type}; |
| 663 | foreach my $proposed_change_properties ( @{ $properties{changes} } ) { |
| 664 | if ( $proposed_change_properties->{add} ) { |
| 665 | if ( $proposed_change_properties->{add} <= |
| 666 | $properties{browser_version} ) |
| 667 | { |
| 668 | if ( !$proposed_change_properties->{pref_name} ) { |
| 669 | if ( !definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $proposed_change_properties->{function_body} ) |
| 670 | { |
| 671 | $proposed_change_properties->{function_body} = |
| 672 | $_function_bodies{ $properties{property_name} } |
| 673 | || 'return null'; |
| 674 | } |
| 675 | $available = $proposed_change_properties; |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | elsif ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $proposed_change_properties->{rm} ) { |
| 680 | if ( $proposed_change_properties->{rm} <= |
| 681 | $properties{browser_version} ) |
| 682 | { |
| 683 | $available = undef; |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | return $available; |
| 688 | } |
| 689 | |
| 690 | sub _this_change_should_be_processedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_this_change_should_be_processed(). { |
| 691 | my ( $class, $proposed_change, $property_name, $change_number, $filters ) = |
| 692 | @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 693 | if ( definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $filters ) { |
| 694 | if ( $property_name !~ /$filters/smx ) { |
| 695 | return 0; |
| 696 | } |
| 697 | } |
| 698 | return 1; |
| 699 | } |
| 700 | |
| 701 | sub _browser_compat_datascip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_browser_compat_data(). { |
| 702 | my ( $class, %parameters ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 703 | my %browser_properties = $class->_read_bcdscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_read_bcd().(); |
| 704 | my $contents = q[]; |
| 705 | my %deleted_classes; |
| 706 | my $change_number = 0; |
| 707 | VERSION: |
| 708 | foreach my $property_name ( sortscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/sort(). { $ascip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$a. cmp $bscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/$b. } keysscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/keys(). %browser_properties ) { |
| 709 | my $property_object = $browser_properties{$property_name}; |
| 710 | my $property_type = $property_object->{type}; |
| 711 | my %from_properties = ( |
| 712 | browser_type => $parameters{from_browser_type}, |
| 713 | browser_version => $parameters{from_browser_version}, |
| 714 | property_type => $property_type, |
| 715 | property_name => $property_name, |
| 716 | changes => $browser_properties{$property_name}{browsers} |
| 717 | { $parameters{from_browser_type} }, |
| 718 | ); |
| 719 | my %to_properties = ( |
| 720 | browser_type => $parameters{to_browser_type}, |
| 721 | browser_version => $parameters{to_browser_version}, |
| 722 | property_type => $property_type, |
| 723 | property_name => $property_name, |
| 724 | changes => $browser_properties{$property_name}{browsers} |
| 725 | { $parameters{to_browser_type} }, |
| 726 | ); |
| 727 | my ( $delete_property, $add_property, $change_properties ); |
| 728 | if ( my $proposed_change_properties = |
| 729 | $class->_available_inscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_available_in().(%from_properties) ) |
| 730 | { |
| 731 | if ( !$class->_available_inscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_available_in().(%to_properties) ) { |
| 732 | $delete_property = 1; |
| 733 | } |
| 734 | } |
| 735 | else { |
| 736 | if ( my $proposed_change_properties = |
| 737 | $class->_available_inscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_available_in().(%to_properties) ) |
| 738 | { |
| 739 | $add_property = 1; |
| 740 | $change_properties = $proposed_change_properties; |
| 741 | } |
| 742 | } |
| 743 | my $to_string_tag_allowed = 0; |
| 744 | if ( |
| 745 | definedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/defined(). $browser_properties{'Symbol.toStringTag'}{browsers} |
| 746 | { $parameters{to_browser_type} }[0]{add} ) |
| 747 | { |
| 748 | if ( $browser_properties{'Symbol.toStringTag'}{browsers} |
| 749 | { $parameters{to_browser_type} }[0]{add} < |
| 750 | $parameters{to_browser_version} ) |
| 751 | { |
| 752 | $to_string_tag_allowed = 1; |
| 753 | } |
| 754 | } |
| 755 | my $change_details = { |
| 756 | to_browser_type => $parameters{to_browser_type}, |
| 757 | delete_property => $delete_property, |
| 758 | add_property => $add_property, |
| 759 | change_number => $change_number, |
| 760 | property_name => $property_name, |
| 761 | property_type => $property_type, |
| 762 | filters => $parameters{filters}, |
| 763 | proposed_change_properties => $change_properties, |
| 764 | deleted_classes => \%deleted_classes, |
| 765 | to_string_tag_allowed => $to_string_tag_allowed, |
| 766 | }; |
| 767 | $contents .= $class->_process_changescip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_process_change().($change_details); |
| 768 | } |
| 769 | return $contents; |
| 770 | } |
| 771 | |
| 772 | sub _process_changescip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_process_change(). { |
| 773 | my ( $class, $change_details ) = @_scip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/`@_`.; |
| 774 | my $contents = q[]; |
| 775 | if ( $change_details->{delete_property} ) { |
| 776 | if ( $change_details->{property_type} eq 'class' ) { |
| 777 | my $proposed_change = $class->_check_and_delete_classscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_delete_class().( |
| 778 | $change_details->{property_name} ); |
| 779 | if ( |
| 780 | $class->_this_change_should_be_processedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_this_change_should_be_processed().( |
| 781 | $proposed_change, |
| 782 | $change_details->{property_name}, |
| 783 | $change_details->{change_number}, |
| 784 | $change_details->{filters}, |
| 785 | ) |
| 786 | ) |
| 787 | { |
| 788 | $contents .= $proposed_change; |
| 789 | $change_details->{deleted_classes} |
| 790 | ->{ $change_details->{property_name} } = 1; |
| 791 | } |
| 792 | } |
| 793 | else { |
| 794 | if ( |
| 795 | my $proposed_change = $class->_check_and_delete_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_delete_function().( |
| 796 | $change_details->{property_name}, |
| 797 | $change_details->{deleted_classes} |
| 798 | ) |
| 799 | ) |
| 800 | { |
| 801 | if ( |
| 802 | $class->_this_change_should_be_processedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_this_change_should_be_processed().( |
| 803 | $proposed_change, |
| 804 | $change_details->{property_name}, |
| 805 | $change_details->{change_number}, |
| 806 | $change_details->{filters}, |
| 807 | ) |
| 808 | ) |
| 809 | { |
| 810 | $contents .= $proposed_change; |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | elsif ( $change_details->{add_property} ) { |
| 816 | if ( $change_details->{property_type} eq 'class' ) { |
| 817 | my $proposed_change = $class->_check_and_add_classscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_class().( |
| 818 | $change_details->{property_name}, |
| 819 | $change_details->{to_string_tag_allowed} |
| 820 | ); |
| 821 | if ( |
| 822 | $class->_this_change_should_be_processedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_this_change_should_be_processed().( |
| 823 | $proposed_change, |
| 824 | $change_details->{property_name}, |
| 825 | $change_details->{change_number}, |
| 826 | $change_details->{filters}, |
| 827 | ) |
| 828 | ) |
| 829 | { |
| 830 | $contents .= $proposed_change; |
| 831 | } |
| 832 | } |
| 833 | else { |
| 834 | if ( |
| 835 | my $proposed_change = $class->_check_and_add_functionscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_check_and_add_function().( |
| 836 | $change_details->{to_browser_type}, |
| 837 | $change_details->{property_name}, |
| 838 | $change_details->{proposed_change_properties}, |
| 839 | $change_details->{deleted_classes} |
| 840 | ) |
| 841 | ) |
| 842 | { |
| 843 | if ( |
| 844 | $class->_this_change_should_be_processedscip-perl cpan Firefox-Marionette 1.70 Firefox/Marionette/Extension/Stealth/_this_change_should_be_processed().( |
| 845 | $proposed_change, |
| 846 | $change_details->{property_name}, |
| 847 | $change_details->{change_number}, |
| 848 | $change_details->{filters}, |
| 849 | ) |
| 850 | ) |
| 851 | { |
| 852 | $contents .= $proposed_change; |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | } |
| 857 | return $contents; |
| 858 | } |
| 859 | |
| 860 | 1; # Magic true value required at end of module |
| 861 | __END__ |
| 862 | |
| 863 | =head1 NAME |
| 864 | |
| 865 | Firefox::Marionette::Extension::Stealth - Contains the Stealth Extension |
| 866 | |
| 867 | =head1 VERSION |
| 868 | |
| 869 | Version 1.70 |
| 870 | |
| 871 | =head1 SYNOPSIS |
| 872 | |
| 873 | use Firefox::Marionette(); |
| 874 | use v5.10; |
| 875 | |
| 876 | my $firefox = Firefox::Marionette->new(stealth => 1); |
| 877 | $firefox->go("https://fastapi.metacpan.org/v1/download_url/Firefox::Marionette"); |
| 878 | |
| 879 | =head1 DESCRIPTION |
| 880 | |
| 881 | This module contains the Stealth extension. This module should not be used directly. It is required when the 'stealth' parameter is supplied to the L<new|Firefox::Marionette#new> method in L<Firefox::Marionette|Firefox::Marionette>. |
| 882 | |
| 883 | =head1 SUBROUTINES/METHODS |
| 884 | |
| 885 | =head2 new |
| 886 | |
| 887 | Returns a L<Archive::Zip|Archive::Zip> of the Stealth extension. |
| 888 | |
| 889 | =head2 user_agent_contents |
| 890 | |
| 891 | Returns the javascript used to setup a different (or the original) user agent as a string. |
| 892 | |
| 893 | =head1 DIAGNOSTICS |
| 894 | |
| 895 | None. |
| 896 | |
| 897 | =head1 CONFIGURATION AND ENVIRONMENT |
| 898 | |
| 899 | Firefox::Marionette::Extension::Stealth requires no configuration files or environment variables. |
| 900 | |
| 901 | =head1 DEPENDENCIES |
| 902 | |
| 903 | None. |
| 904 | |
| 905 | =head1 INCOMPATIBILITIES |
| 906 | |
| 907 | None reported. |
| 908 | |
| 909 | =head1 BUGS AND LIMITATIONS |
| 910 | |
| 911 | To report a bug, or view the current list of bugs, please visit L<https://github.com/david-dick/firefox-marionette/issues> |
| 912 | |
| 913 | =head1 AUTHOR |
| 914 | |
| 915 | David Dick C<< <[email protected]> >> |
| 916 | |
| 917 | =head1 LICENSE AND COPYRIGHT |
| 918 | |
| 919 | Copyright (c) 2024, David Dick C<< <[email protected]> >>. All rights reserved. |
| 920 | |
| 921 | This module is free software; you can redistribute it and/or |
| 922 | modify it under the same terms as Perl itself. See L<perlartistic/perlartistic>. |
| 923 | |
| 924 | =head1 DISCLAIMER OF WARRANTY |
| 925 | |
| 926 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
| 927 | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
| 928 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
| 929 | PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
| 930 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 931 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
| 932 | ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
| 933 | YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
| 934 | NECESSARY SERVICING, REPAIR, OR CORRECTION. |
| 935 | |
| 936 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
| 937 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
| 938 | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
| 939 | LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
| 940 | OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
| 941 | THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
| 942 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
| 943 | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
| 944 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
| 945 | SUCH DAMAGES. |