Bug 136081 - Safari fails on request to a non-authenticated API
Summary: Safari fails on request to a non-authenticated API
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P3 Normal
Assignee: Nobody
URL: https://github.com/angular/angular.js...
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-19 11:30 PDT by Cory.Shaw.Dev
Modified: 2015-04-02 13:58 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cory.Shaw.Dev 2014-08-19 11:30:53 PDT
When attempting to make a $http.get(AngularJS) request or any Ajax get request in Safari the following error log occurs. This same get request works in all other major browsers. Feel free to see the full code here: https://github.com/coryshaw1/ng-soundcloud-playlist

//SoudcloudService
vm.embed = function( trackUrl ) {
    vm.trackUrl = trackUrl;
    vm.url = 'http://api.soundcloud.com/oembed?format=json&url=' + vm.trackUrl + '&auto_play=true&maxheight=200';

    return $http.get(vm.url); //Example url: http://api.soundcloud.com/oembed?format=json&url=http://soundcloud.com/flume/seekae-test-recognise-flume-re-work&auto_play=true&maxheight=200
};
...

//Calling in controller
SoundcloudService.embed( vm.list[index].permalink_url )
    .success(function(data, status) {
        vm.loading = false;
            vm.embedHtml = $sce.trustAsHtml(data.html); //Is HTML5 iframe so handle javascript
    }).error(function(data, status, headers, config) {
        vm.loading = false;
        var configText = function(){
                var output = '';
                for (var property in config) {
                  output += property + ': ' + config[property].toString()+'\n ';
                }
                return output;
              }
              var headersText = function(){
                var output = '';
                for (var property in headers) {
                  output += property + ': ' + headers[property].toString()+'\n ';
                }
                return output;
              }
              console.log('Status:', status,
                            '\nData:', data, 
                            '\nHeaders:', headersText(), 
                            '\nConfig:', configText());
    });

//Console log
Failed to load resource: https://soundcloud.com/oembed?format=json&url=http://soundcloud.com/flume/seekae-test-recognise-flume-re-work&auto_play=true&maxheight=200 Cannot make any requests from null.

XMLHttpRequest cannot load https://soundcloud.com/oembed?format=json&url=http://soundcloud.com/flume/seekae-test-recognise-flume-re-work&auto_play=true&maxheight=200. Cannot make any requests from null.

Status: 0 
Data:  
Headers: Empty Object
Config: 
    method: GET
    transformRequest: function (d) {
      return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d;
    }
    transformResponse: function (data) {
      if (isString(data)) {
        // strip json vulnerability protection prefix
        data = data.replace(PROTECTION_PREFIX, '');
        if (JSON_START.test(data) && JSON_END.test(data))
          data = fromJson(data);
      }
      return data;
    }
    url: http://api.soundcloud.com/oembed?format=json&url=http://soundcloud.com/flume/seekae-test-recognise-flume-re-work&auto_play=true&maxheight=200
    headers: Empty Object
Comment 1 Cory.Shaw.Dev 2014-08-19 13:27:43 PDT
I made a live build you can test with here: http://coryshaw.us/ngSouncloudPlaylist/

Search for any track title, then you should get the error when clicking "Play" next to any song.
Comment 2 Cory.Shaw.Dev 2014-08-19 13:28:37 PDT
(In reply to comment #1)
> I made a live build you can test with here: http://coryshaw.us/ngSouncloudPlaylist/
> 
> Search for any track title, then you should get the error when clicking "Play" next to any song.

http://coryshaw.us/ngSoundcloudPlaylist/ sorry typo..
Comment 3 Kevin Lee 2015-04-02 13:58:38 PDT
I'm experiencing the same issue with the following code snippet:

$http({
                method: 'post',
                url: $scope.service !== 'Photography' ? 'https://script.google.com/macros/s/identifyinginformationhere/exec' : 'https://script.google.com/macros/s/differentinformationhere/exec',
                params: dict
            })
            .success(successf)
            .error(errorf);


which generates the following three debugging output:

[Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
[Error] Failed to load resource: Cannot make any requests from null.
XMLHttpRequest cannot load https://script.googleusercontent.com/macros/echo?user_content_key=moredifferentinformationhere. Cannot make any requests from null.

It seems to be a CORS issue. This code works in all other browsers, just like Cory's. The request actually makes it through, because I can see modifications on the Google spreadsheet the request POSTs to, but unlike the other browsers I get a 405 and error runs. On chrome I get a 302 and successf runs.