philschatz / octokat.js

:octocat: Github API Client using Promises or callbacks. Intended for the browser or NodeJS.
http://philschatz.com/2014/05/25/octokat/
MIT License
421 stars 133 forks source link

Error: TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation #180

Closed moghya closed 7 years ago

moghya commented 7 years ago

I'm trying to use Octokat for a simple purpose, I tried examples for browser and getting this error. I understand using callbacks is intended use but in that case, every time I'm getting the undefined result.

Please help.

moughxyz commented 7 years ago

I'm also getting this same issue using this code and octokat 0.9.0.

<html>
  <body>
    <script src="./bower_components/octokat/dist/octokat.js"></script>
    <script>
      var octo = new Octokat();
      octo.repos('philschatz', 'octokat.js').fetch(function(err, repo) {
        if (err) { return alert(err); }
        alert(repo.url); 
      });
    </script>
  </body>
</html>
philschatz commented 7 years ago

In 0.9 octokat switched to using the Fetch API which may require using a fetch polyfill.

It seems README.md should be updated to clarify this because it seems that Internet Explorer does not support window.fetch(...)

Does the fetch polyfill help resolve this problem?

azu commented 7 years ago

Same issue on Chrome 58.0.3029.110 (64-bit).

TypeError: 'fetch' called on an object that does not implement interface Window.

Firefox get the above error on my app

I found a workaround:

const Octokat = require("octokat");
Octokat.Fetch = (...args) => {
    return window.fetch(...args);
};

Should this of fetch be window?

Similar issues?

metasong commented 7 years ago

try the 2 suggestions, still not work. donwgrade to version 0.8 solved my problem!

philschatz commented 7 years ago

Thanks for reporting this and sorry about the late reply.

Oops 😊 ! This was missed in the tests because they use a different implementation of fetch that does not raise this error. It should be resolved in 0.9.1.

You can also include Octokat.Fetch = window.fetch.bind(window) to get around the issue.

philschatz commented 7 years ago

Closing for now but if this problem still occurs please comment.