Protip: in the developer tools of Beaker (view → Toggle DevTools) in the “Console” section. You can type javascript code directly inside the console. Type “window.safe” to see the Safe API exposed by the browser.
I’ve just updated the readme now, which should clarify some things, as well as updating the outdated initial example.
So safe-js can be used in node, or any browser, and that would use methods as listed in the readme.
However, when using the SAFE Browser, these methods are baked into the window object, which means 1) they run internally in the background in beaker, and 2) you dont need to include your own copy of safe-js, they are automatically (and only) available to safe: sites.
So your example here, when uploaded to the network, should look like:
Before uploading to the neteork, you’ll need to test these same methods, which is why there’s a window.safeX polyfill available in the npm package. As described over here.
Is that code you supplied supposed to work in the console? It looks like the window function of “authorise” can’t work that way, is this what @joshuef was talking about for the “polyfill” thing (which I’m still not quite clear on what it is)?
I’m guessing not, and will try it in a hosted SAFE page now
Thanks for helping me along, still can’t seem to get it to work though. This is my newest javascript attempt, and it is all running from SAFE (at this Alphanet link safe://appzerosafejs.bigbang/) and my dev console keeps saying “unexpected token import” even though I’ve removed all the LOCAL_TOKEN etc code. Not sure what to make of it here. Just trying to learn the flow of safe-js’s tools
Your safejs code looks good in itself (and as you note, with the latest version of the browser/safejs, you don’t need to supply a token as it will be overridden by the url of the site in beaker anyway).
So to get this code running, I think you only need remove those two lines.
I must be doing something wrong? I know there have been changes made to how tokens are used @joshuef@happybeing do you think this has anything to do with APP ZERO never working in safe-js yet?
Well for me personally it’s a good entry point into safe-js for uploading files etc. I think a web app replacement of the demo app will be a great thing, since all you need to do with it is create public / private folders, upload files, and map dns. Should take some burden off MaidSafe if I can get it done.
In general, everyone should take it every Direction they can! SAFE apps need to be built! Replace clearnet in every use case
Don’t forget, APP ZERO is all about the BARE MINIMUM needed to be a SAFE (web) app that just authenticates with the Network. Just one HTML file with some JS for the commands will suffice!!