First Steps with Beaker and safe-js App Development

Hi @joshuef, I’m playing around with the safe api on SAFE Browser, pretty cool work. I manage to authenticate and create a file but when I try to get it back I get the following error:

Uncaught (in promise) Error: Unexpected token a in JSON at position 0(…)

My call looks like this:

window.safeNFS.getFile(token, "test");

Any idea?

EDIT: Is there a debug mode to see the content of the request that goes to the launcher?

1 Like

If you use the polyfill network requests to launcher are visible in the debugger, as before.

You are just ahead of me here - I did safe-js auth last night, but still using XmlHttpRequest for everything else!

1 Like

So polyfill.js is to get the same window.safexxx api inside another browser like chrome right? Is that how you use it, not directly inside the Safe Browser?

No, polyfill.js is for SAFE Browser - it allows you to run locally, either as file:// (not tried) or using a local web server (e.g. as localhost:8000).

Also, you can set a breakpoint in your call (above) and step in to see exactly what is going to Launcher. Did this last night.

You’ll need to turn off CORS checks to work locally though, within SAFE Beaker (toolbar button / menu item).


Okay thanks, where do you get polyfill from?

It’s part of safe-js, see above:

EDIT: I’m on slack at the moment if you want anything.


Oh wow, ok I installed safe-js through npm and it generated a gazillion files! Damn, lol, I’m a bit surprised, polyfill itself is six thousands lines long. Is that all necessary? I guess for development that could work.

i really don’t like using node/browser hydrid code, these things are a visual abomination eheh. Anyway enough rant, thanks for the info.

Likewise. npm = vomit lol

I’m just looking at safe-js NFS now and I think you’re getFile is missing some parameters, here’s the getFile function definition:

export const getFile = function( token, filePath, isPathShared = false ) {

I’m a bit surprised it is defined like this but haven’t used it myself yet. So here goes lol.


Good idea.

I don’t think the problem is with the parameter, isPathShared has a value by default so it’s optional. The token I use is the one from authorise and the filepath is just the same name of the file I created before. Seems to be an internal error. I’ll dive a little deeper.

EDIT: Oh, maybe I’m not using the correct version of the launcher. I’ll have to check that out later.

1 Like

Sorry, I thought you were missing ‘token’, didn’t check. My memory! :slight_smile:

1 Like

Just saw this!

Do you see the launcher logs as well? Does it receive a request? And does that succeed or fail on the launcher?

It could be that the launcher is returning an error, and that’s causing safe-js errors. (Improving safe-js error logging it on the list! sorry, I’m aware it’s a bit of a pain right now).