+
Skip to content

btoa not found (when running from a browser) #178

Closed
@jgbarah

Description

@jgbarah

Tested with "Firefox 38.0" and "Chromium Version 38.0.2125.101 Built on jessie/sid, running on Debian jessie/sid (290379)". When trying to write to a new file, I get an error about btoa not found.

var github = new Github({
    token: token,
    auth: "oauth"
});
var repo = github.getRepo(user, reponame);
repo.write('master', 'data', "Hola", "First", function(err) {});

The error happens in the repo.write line. If instead of that one I have the wollowing one:

repo.show(showRepo);

It calls showRepo, which is a function that shows the info about the repo perfectly.

After a bit of debugging, it seems that the problem is that btoa is not available at the moment of calling "write", but is needed by it.

Changing all invoking occurences of "btoa" to "window.btoa" in github.js, (three occurrences in total) fixes this. But I'm not sure this is the best way of fixing it, since it will probably not run if not in a browser... In addition, I see the code

  if (typeof exports !== 'undefined') {
      XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
      _ = require('underscore');
      var btoa = require('btoa'); //jshint ignore:line
  } else { 
      _ = window._; 
  }

which maybe is set up for exactly this scenario, but I'm not sure why it is not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载