Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Parse RestAPI in Unity WebGL build not working on Google Chrome

Discussion in 'WebGL' started by Binex-UmairBhatti, Jan 25, 2016.

Thread Status:
Not open for further replies.
  1. Binex-UmairBhatti

    Binex-UmairBhatti

    Joined:
    Nov 8, 2013
    Posts:
    8
    I am trying to integrate Parse in Unity Webgl build. As there is no specific SDK for WebGL provided by parse so for parse communication i am using RestAPI to Get the data from parse. As provided in parse help first i have created a user at the parse dashboard. Using those credentials i first login to the parse from the app using following code:

    WWWForm form = new WWWForm();
    var headers = form.headers;
    headers["X-Parse-Application-Id"] = ParseHandler.Instance.ApplicationID;
    headers["X-Parse-REST-API-Key"] = ParseHandler.Instance.RestApiKey;
    headers["Content-Type"] = "application/json";

    WWW www = new WWW("https://api.parse.com/1/login?username=abc&password=abcpassword", null, headers);
    yield return www;
    if (www.error != null)
    {
    isInitialized = false;
    }
    else
    {
    isInitialized = true;
    }

    After login in successfully i try to get the data of specific person using following code:

    WWWForm form = new WWWForm();
    var headers = form.headers;
    headers["X-Parse-Application-Id"] = ParseHandler.Instance.ApplicationID;
    headers["X-Parse-REST-API-Key"] = ParseHandler.Instance.RestApiKey;
    headers["Content-Type"] = "application/json";
    WWW www = new WWW("https://api.parse.com/1/classes/PlayerProfile?where={\ "ID\ ":\ "20489\ "}",null,headers);

    if (www.error != null)
    {
    if (responseDelegate != null)
    responseDelegate(null);
    }
    else
    {
    if (responseDelegate != null)
    responseDelegate(www.text);
    }


    When i open this WebGL build on Firefox after login in to facebook parse starts initializing and it works perfectly fine. It do login and get the data but when i try to Open the build on Google Chrome it gives following error and parse doesn’t able to login or get data from parse:
    Refused to set unsafe header "User-Agent"

    Please help how can i fix this issue. As we don’t want to shift this app to webplayer as chrome doesn’t support webplayer, also it has a prerequisite of downloading unity webplayer and all our data is already maintained on parse for different platforms.

    I have hosted the app at the following link :
    https://www.leatherjacketmaster.com/goa/index.html”
     
  2. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    I believe you are not able to set unsafe headers like user-agent for XMLHttpRequest in Chrome directly due to a security restriction. There are of course workarounds for this, for example, you can set a dummy header like _user-agent instead, and replace it with user-agent while passing the request through a proxy. The thing is that I was able to launch the game on Chrome (47, 64-bit, Mac) and although the user-agent header is not set properly, the requests seem to work just fine. Which Chrome version are you using exactly (Win/Mac/32/64)?

    Btw, you might consider reducing the TOTAL_MEMORY to like 512 MB, otherwise you might experience some difficulties loading the game in 32-bit Chrome.
     
    Last edited: Jan 25, 2016
  3. Binex-UmairBhatti

    Binex-UmairBhatti

    Joined:
    Nov 8, 2013
    Posts:
    8
    Thank for the reply alexsuvorov. That was really helpful because of the error, I was trying different User-Agent values which was causing the issue. Now I have removed the User-Agent key from the headers, it still gives the same error but i am getting the response from the parse server as well. I was using Chrome(48.0.2564.82 (64-bit)) on Mac.

    Thanks for the alarming me for reducing the memory i will look in to it and will try to reduce it.

    One last thing do you think that the error i am getting regarding User-Agent will cause anything wrong? or its now just a warning error?
     
  4. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    It is a warning that informs you that Chrome has not set the user-agent header, it does not prevent the request from being performed. The only difference is that the Chrome request will be performed with for example:
    user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36
    instead of the intended:
    user-agent: FBJSSDK/v2.5 FBUnityWebGL/7.2.2 FBUnitySDK/7.2.2
    If the server response depends on the user-agent value, then you might consider using workaround mentioned above. Otherwise you may just ignore this warning.
    I was able to connect both using Chrome and Firefox and I can see the likes displayed in both browsers. Could you point out what exactly is the functional difference between Chrome and Firefox gameplay that indicates the issue?
     
Thread Status:
Not open for further replies.