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

后端 未结 6 1111
广开言路
广开言路 2020-12-06 00:04

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 architectu

相关标签:
6条回答
  • 2020-12-06 00:36

    about:config - > general.platform.override

    0 讨论(0)
  • 2020-12-06 00:40

    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.

    0 讨论(0)
  • 2020-12-06 00:48
    var fakePlatformGetter = function () {
      return "your fake platform";
    };
    if (Object.defineProperty) {
      Object.defineProperty(navigator, "platform", {
        get: fakePlatformGetter
      });
      Object.defineProperty(Navigator.prototype, "platform", {
        get: fakePlatformGetter
      });
    } else if (Object.prototype.__defineGetter__) {
      navigator.__defineGetter__("platform", fakePlatformGetter);
      Navigator.prototype.__defineGetter__("platform", fakePlatformGetter);
    }
    
    0 讨论(0)
  • 2020-12-06 00:49

    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.

    0 讨论(0)
  • 2020-12-06 00:54

    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.

    0 讨论(0)
  • 2020-12-06 01:02

    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.

    0 讨论(0)
提交回复
热议问题