How to change userAgent name when opening sites?

0 favourites
  • 6 posts
  • Tell me, how can I change the userAgent when opening a site in iframe? It is very necessary to add specialized information for processing on the server side.

    Previously, I was able to use this code, but it didn’t work in the Construct:

  • I don't think browsers actually allow this. I think it could cause a lot of compatibility and security issues if pages could arbitrarily change the browser user agent.

    If you want to specify some extra data to handle on the server side, usually you'd do that with query string parameters or POST data.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This could do the trick

    alert(navigator.userAgent);
    alert(navigator.appName);
    
    navigator.__defineGetter__('userAgent', function () {
     return "Prince Pie"
    });
    navigator.__defineGetter__('appName', function () {
     return "Mehlicious"
    });
    
    alert(navigator.userAgent);
    alert(navigator.appName);
    
    
  • I don't think browsers actually allow this. I think it could cause a lot of compatibility and security issues if pages could arbitrarily change the browser user agent.

    If you want to specify some extra data to handle on the server side, usually you'd do that with query string parameters or POST data.

    Changing the name in the userAgent is a common practice, for example, almost all bots use it.

    Then you can configure the rules on the nginx server itself.

  • This could do the trick

    > 
    alert(navigator.userAgent);
    alert(navigator.appName);
    
    navigator.__defineGetter__('userAgent', function () {
    return "Prince Pie"
    });
    navigator.__defineGetter__('appName', function () {
    return "Mehlicious"
    });
    
    alert(navigator.userAgent);
    alert(navigator.appName);
    
    

    The code I've suggested does a great job of making changes to the userAgent.

    Your version of the code also makes changes to the userAgent.

    But the construct ignores the user data in the userAgent and uses others:

    whatsmyua.info

  • I meant web content can't change the actual browser user agent.

    You can override the local JavaScript string in navigator.userAgent but it just overwrites it for the current page, it doesn't actually change the browser user agent.

    Bots that customise the user agent string do it by altering the browser itself. I don't think normal web pages have that control. So I think it's impossible from JS code.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)