How can I fool a site that looks at the JavaScript object 'navigator' to see that I'm not on Windows?

大城市里の小女人 提交于 2019-11-26 23:13:45

问题


I am trying to browse a website, however, it only works under Windows and Mac because they use the navigator.platform from JavaScript to find out the architecture I am running on. Of course, they also use the browser's user agent, but that was easy to spoof.

Here is the .js in question: http://pastebin.com/f56fd608d. The code responsible for browser detection is at the top. Is there any way of changing the .js file before the site runs, or something similar, so I can eliminate the check?

Using the JavaScript console yields:

>navigator.platform
Linux i686

Evidently I changed the browser's user agent, but navigator.platform does not seem to take it's value from the user agent.

Maybe someone knows how to change the value returned by navigator.platform, because I hate running Windows under VirtualBox to use this site.

EDIT: This could be of interest because Linux users might be artificially denied access to websites, and can do nothing about it.


回答1:


Since you can't directly set navigator.platform, you will have to be sneaky - create an object that behaves like navigator, replace its platform, then set navigator to it.

var fake_navigator = {};

for (var i in navigator) {
  fake_navigator[i] =  navigator[i];
}

fake_navigator.platform = 'MyOS';

navigator = fake_navigator;

If you execute this code before the document loads (using GreaseMonkey, an addon or a Chrome extension), then the page will see navigator.platform as "MyOS".

Note: tested only in Chrome.




回答2:


var fakePlatformGetter = function () {
  return "your fake platform";
};
if (Object.defineProperty) {
  Object.defineProperty(navigator, "platform", {
    get: fakePlatformGetter
  });
} else if (Object.prototype.__defineGetter__) {
  navigator.__defineGetter__("platform", fakePlatformGetter);
}



回答3:


about:config - > general.platform.override




回答4:


For a Mozilla-based browser, GreaseSpot / Code Snippets # Hijacking browser properties demonstrates how it may be done. This code may be injected from a GreaseMonkey script.




回答5:


Provided that the browser you're using supports Object.defineProperty() (it likely does), a more modern way of achieving the same goal is as follows:

Object.defineProperty(navigator, 'platform', {
  value: 'my custom value',
  configurable: true // necessary to change value more than once
});

This allows you to set it to any custom value you want, and it also allows you to change it as many times as you want without needing to reload the page.




回答6:


Attempting to change this property (at any time) in Firefox yields:

Error: setting a property that has only a getter

Source File: index.html

Line: 1

So I think you will have a hard time.

I'd try to contact the author about obtaining a fix.



来源:https://stackoverflow.com/questions/2166540/how-can-i-fool-a-site-that-looks-at-the-javascript-object-navigator-to-see-tha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!