admin管理员组

文章数量:1392110

im trying to spoof ExternalInteface.call("window.navigation.userAgent.toString") to look like a electron environment using the javascript below. though it works for the browser it keeps returning this in flash: "the thing it got is Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.0) Gecko/20100101 Goanna/6.7 Firefox/115.0 Basilisk/20250220"

i cant modify the swf file since its taken from a server, which if i use my local one some login authentication breaks. the base swf runs from an electron environment and it does an update check if the electron environment is outdated. by checking its version, anything less then 1.5.3 it will show a update screen

   Object.defineProperty(navigator, "userAgent", {
        get: function () {
          return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Electron/9.0.0";
        },
        configurable: true
    });
    console.log(window.navigator.userAgent.toString());

the flash script gets the user agent like this

    public static function getUserAgent() : String
    {
        var _loc1_:String = null;
        if(ExternalInterface.available)
        {
            _loc1_ = ExternalInterface.call("window.navigator.userAgent.toString");
        }
        return _loc1_;
    }

I tried a couple of things.

thought maybe the flash environment would use some other weird function calling

    window.getUserAgent = function() {
        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Electron/9.0.0 ";
    };`

also tried directly setting the user agent

    window.navigator.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Electron/9.0.0"

so im working on the web. i need to make it so the swf thinks its in a electron enviroment. it does this check using this.

      public static function getUserAgent() : String
      {
         var _loc1_:String = null;
         if(ExternalInterface.available)
         {
            _loc1_ = ExternalInterface.call("window.navigator.userAgent.toString");
         }
         return _loc1_;
      }
      public static function getElectronVersion() : String
      {
         var _loc2_:Array = null;
         var _loc1_:String = getUserAgent();
         if(_loc1_ != null)
         {
            _loc2_ = _loc1_.match(/GameVer(Dev|Stage)?\/(\d+\.\d+\.\d+)/);
            if(_loc2_ != null && _loc2_.length > 0)
            {
               return _loc2_[_loc2_.length - 1];
            }
         }
         return null;
      }
public static function isElectronVersionIncompatible() : Boolean
      {
         var _loc3_:Array = null;
         var _loc2_:Array = null;
         var _loc4_:int = 0;
         var _loc1_:String = getElectronVersion();
         if(_loc1_ != null)
         {
            _loc3_ = _loc1_.split(".");
            _loc2_ = "1.5.3".split(".");
            if(_loc3_.length == _loc2_.length)
            {
               _loc4_ = 0;
               while(_loc4_ < _loc3_.length)
               {
                  if(_loc3_[_loc4_] < _loc2_[_loc4_])
                  {
                     return true;
                  }
                  _loc4_++;
               }
               return false;
            }
         }
         return getUserAgent() != null;
      }

it does this check to see if you need to update the application

            if(!gMainFrame.clientInfo.df || Utility.isElectronVersionIncompatible())
            {
               showUpdateRequired();
               return;
            }

gMainFrame.clientInfo.df is just the machines id

im trying to spoof ExternalInteface.call("window.navigation.userAgent.toString") to look like a electron environment using the javascript below. though it works for the browser it keeps returning this in flash: "the thing it got is Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.0) Gecko/20100101 Goanna/6.7 Firefox/115.0 Basilisk/20250220"

i cant modify the swf file since its taken from a server, which if i use my local one some login authentication breaks. the base swf runs from an electron environment and it does an update check if the electron environment is outdated. by checking its version, anything less then 1.5.3 it will show a update screen

   Object.defineProperty(navigator, "userAgent", {
        get: function () {
          return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Electron/9.0.0";
        },
        configurable: true
    });
    console.log(window.navigator.userAgent.toString());

the flash script gets the user agent like this

    public static function getUserAgent() : String
    {
        var _loc1_:String = null;
        if(ExternalInterface.available)
        {
            _loc1_ = ExternalInterface.call("window.navigator.userAgent.toString");
        }
        return _loc1_;
    }

I tried a couple of things.

thought maybe the flash environment would use some other weird function calling

    window.getUserAgent = function() {
        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Electron/9.0.0 ";
    };`

also tried directly setting the user agent

    window.navigator.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Electron/9.0.0"

so im working on the web. i need to make it so the swf thinks its in a electron enviroment. it does this check using this.

      public static function getUserAgent() : String
      {
         var _loc1_:String = null;
         if(ExternalInterface.available)
         {
            _loc1_ = ExternalInterface.call("window.navigator.userAgent.toString");
         }
         return _loc1_;
      }
      public static function getElectronVersion() : String
      {
         var _loc2_:Array = null;
         var _loc1_:String = getUserAgent();
         if(_loc1_ != null)
         {
            _loc2_ = _loc1_.match(/GameVer(Dev|Stage)?\/(\d+\.\d+\.\d+)/);
            if(_loc2_ != null && _loc2_.length > 0)
            {
               return _loc2_[_loc2_.length - 1];
            }
         }
         return null;
      }
public static function isElectronVersionIncompatible() : Boolean
      {
         var _loc3_:Array = null;
         var _loc2_:Array = null;
         var _loc4_:int = 0;
         var _loc1_:String = getElectronVersion();
         if(_loc1_ != null)
         {
            _loc3_ = _loc1_.split(".");
            _loc2_ = "1.5.3".split(".");
            if(_loc3_.length == _loc2_.length)
            {
               _loc4_ = 0;
               while(_loc4_ < _loc3_.length)
               {
                  if(_loc3_[_loc4_] < _loc2_[_loc4_])
                  {
                     return true;
                  }
                  _loc4_++;
               }
               return false;
            }
         }
         return getUserAgent() != null;
      }

it does this check to see if you need to update the application

            if(!gMainFrame.clientInfo.df || Utility.isElectronVersionIncompatible())
            {
               showUpdateRequired();
               return;
            }

gMainFrame.clientInfo.df is just the machines id

Share Improve this question edited Mar 12 at 12:06 ThatonehamYT asked Mar 12 at 8:59 ThatonehamYTThatonehamYT 11 bronze badge 7
  • Welcome to SO. It looks as if you have a xy-problem. Why do you have to "trick" your Actionscript/Flash to "think" it runs inside an Electron application? – Davi Commented Mar 12 at 10:40
  • Well, the swf file i cant modify since its taken from a server, which if i use my local one some login authentication breaks. the base swf runs from an electron environment and it does an update check if the electron environment is outdated. by checking its version, anything less then 1.5.3 it will show a update screen. – ThatonehamYT Commented Mar 12 at 10:58
  • Fine - but what is the behavior you want to change? Do you want to suppress the update check somehow? Because if your application has been build with an electron version before 1.5.3, IMHO it would be better to rebuild the application with a newer version of electron. – Davi Commented Mar 12 at 11:34
  • No im porting it to the web. thats why im trying to spoof the user agent. – ThatonehamYT Commented Mar 12 at 11:36
  • In that case please keep in mind that support for Flash has already been dropped by all major browsers as well as Adobe itself years ago. Therefor it's very likely that there's a lot of users that cannot even play the SWF, even if you manage to port it to the browser. Regarding your question: The userAgent is read-only according to MDN. However, the browser allows to change it via the settings, so that might be an option for you until you've ported it. – Davi Commented Mar 12 at 14:05
 |  Show 2 more comments

1 Answer 1

Reset to default 0

Had to add in about:config "general.useragent.override.localhost" to what the flash file wanted. GameVerStage/9.9.9

本文标签: