Search Unity

CORS on Edge when trying to fetching facebook photo (WebGL)

Discussion in 'Web' started by jpfortin_bhvr, Aug 17, 2018.

  1. jpfortin_bhvr

    jpfortin_bhvr

    Joined:
    Jul 3, 2018
    Posts:
    3
    Hey, I'm having a hard time to load a facebook profile picture on Microsoft Edge browser.
    Edge is the only one giving me this CORS problem.

    Here what I'm doing:

    UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(url);
    webRequest.SetRequestHeader("Access-Control-Allow-Origin", "*");
    yield return webRequest.SendWebRequest();


    It work on every other browser.

    I'm using unity 2017 latest version.
     
    Last edited: Aug 20, 2018
  2. jpfortin_bhvr

    jpfortin_bhvr

    Joined:
    Jul 3, 2018
    Posts:
    3
  3. n0rvig

    n0rvig

    Joined:
    Sep 27, 2017
    Posts:
    1
    Me too. We're using the Facebook SDK to get the pictures, but they still aren't working.

    @jpfortin_bhvr did you have any success with this, or did you switch to proxying the pictures? Which seems like the only workaround left for us.

    Also did you experiment switching between HTTP and HTTPS?
     
  4. chyrho

    chyrho

    Joined:
    Nov 1, 2016
    Posts:
    3
    This is an old topic but I'd still like to share my findings.

    Firstly jpfortin_bhvr you should NOT add Access-Control-Allow-Origin header in your request. It's supposed to be a response header. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin. A HTTP request should set "origin" header instead. Origin header is supposed to be set automatically by the browser based on CORS rule.

    I noticed that the same issue before. When requesting Facebook profile icons (URLs like https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=xxxx&...), Facebook returns correct image if the request is from any browser other than Edge.

    For Edge, if the request included "origin" header, Facebook always returned a HTTP 302 redirection to a strange Facebook page rendering a human-readable message "Your Request Couldn't be Processed". When origin header was not part of the request sent from Edge, Facebook returned correct image as well.

    The only explanation is somehow FB had a server-side logic treating different user agent + origin differently. This is definitely not a Unity bug.

    When I tested it again today, the issue appears to be gone now. I think FB has fixed it.
     
    Last edited: Oct 16, 2019