Safe Browser Dev Updates (@v0.4.2)

I now have a similar problem with the function getFile. The object it returns isn’t the body of the file I’m requesting. Instead, it’s an object that describe the response: status:200, statusText: OK, etc. But it doesn’t seem to contain the body of the file.

safe://simplesafe2.davidmtl/ (testnet 11)

My code looks like this:

window.safeNFS.getFile(token, filename).then(function(response) {
        console.log(response);
    }).catch(function(error) {
        console.log("ERROR:" + error);
    });

I’m using the same version of beaker so this should be fine. Here is my code which definitely retrieves files that I’ve stored:

https://github.com/theWebalyst/remotestorage.js/blob/feature/safestore-backend-gd/src/safenetwork.js#L358-L386

1 Like

Strange, the call we make looks the same but the object I get in the response looks like this:

Btw, how do you quote a piece of code from github like that?

I think I might know why there’s a difference… as we’re on localhost you’re probably using the polyfill.js? If so, you may need to grab the latest one from github because there were some fixes and I might be using a later version - although just looking at some PM’s with @joshuef I think they have been included in the latest beaker so this may not be the reason. I think I’ll leave this for Josh.

To quote on github you can view a code file and then click on a line number and the URL will be updated to highlight that line - so then select and copy the URL. To select a range Click on the first line number, and then Shift-Click on the second.

2 Likes

I’m not sure I understand what the polyfill is but the example I did run on the testnet, here. If yours is run from the filesystem directly that could explain the difference as you say.

1 Like

Ok, its not the polyfill then - you’d know what I meant. I have the above code running with and without the polyfill, so my code and yours should do the same live on the network (Test 11 that is - I’m not using the alpha).

1 Like

Hey @DavidMtl, so most functions will parse the reponse to give the clear result from the api. Only the file endpoints will return a full response as these can be used in a few different ways by the app (depending on type of file/size etc), so parsing these responses is currently left to the app.

for example:

safejs.nfs.getFile( token, dirName + '/' + fileName ).then( response =>
        {
            response.text().then( text => {console.log('The text of your file, if it was a text file:',text)}) 
        });

Hope that helps/clarifies.

As ever, if you think docs can be updated for clarity pop an issue on the repo or PR. Happy for all input!

2 Likes

@DavidMtl more detail here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Body

1 Like

I have some safe-js examples that are the beginnings of a test suite against the network. I’ll tidy this up, and provide some notes on how this should roll in Safe Browser, and that should hopefully clarify a lot of stuff.

I’ll get into that just after I’ve got the last kinks out of the sync setup.

2 Likes

WoW that’s a lot of work, thank you for doing that each testnet for us!

Does “fell” mean the websites you successfully found through guessing?

Yes me either. Sounded like a way to fill in your functions for local testing but I’m not sure how to use it

Safe Browser w/ sync. Pre-release for testing v0.4.0-3

I’ve pushed the latest version of the SAFE Browser that will sync to the network if/when authorised.

All beaker sql endpoints have been converted, so:

  • history
  • favourites (bookmarks)
  • sitedata
  • settings

are now stored on the network :boom:

Using these features.

Right now, the best way (due to beakers lack of shortcuts) for adding favourites, sitedata etc is via the console:

window.beakerBookmarks.add('<siteurl>','<sitetitle>')
beakerSitedata.set('<url>','<key>','<token>')
beakerSitedata.get('<url>','<key>')

The sitedata methods are analogous to standard browser localStorage, but on the network itself (localStorage itself will save to the computer)

History should update by itself, as you would expect.

Caveats

This version is not ready for general use. There will likely be a variety of bugs with syncing, so please only dive in here if you’re ready to help debug such things :smiley:

Aside from a refactor, just testing various use cases and looking for network errors is the most important thing here. So keep an eye on your Launcher logs. If you are having problems, it’s probably best to download and build from source to get a clearer look at errors. (both syncing, and triggering auth etc).

Known Issues

Rapidly adding / changing data results in mutation errors on the network. I’m investigating the best ways to handle these.

The redux store and async save flow is reasonably stable now in bookmarks. I need to refactor site-data etc to work in the new fashion.

The safe-status page doesn’t currently update, you’ll have to refresh to see the current status.

Refactoring

Right now the code has a couple of different flows for data storage, bookmarks being the latest and most robust in terms of the app and network. I’m planning to refactor everything to a common pattern, like this.

There’s also the ‘safe-status’ page, which currently, you have to refresh to see updates. This can be easily refactored for a release, but for dev there’s limitations on debugging right now with this in place.

Todos for BrowserSync:

  • Update SAFE Status and browser pages upon data change.
  • Implement error reporting and retry save/auth network errors
  • Refactor reducers and stores.
4 Likes

Is this what’s supposed to happen? Tried a few ways:

1 Like

Yup. Then if you check the ‘favourites’ page (accessed via opening a new tab) you should see it added.

You can check for a file write in the launcher logs too.

2 Likes

Hey @joshuef, I’m getting a response.text is not a function with this code. I’m using browser v3.6-0. You can see my code here: safe://simplesafe2.davidmtl/

Any idea what I’m doing wrong?

1 Like

Can you post the code you’re using here? (your site wont load for me)

Are you seeing any launcher interactions / logs?

That’s strange. I’m using launcher 0.9.3 and browser 0.3.6. Here’s the code:

var filename = document.getElementById("filename").value;

window.safeNFS.getFile( token, filename ).then( response =>
{
    response.text().then( text => {console.log('The text of your file, if it was a text file:',text)})
}).catch(function(error) {
    console.log(error);
});

Yes, authorization, creating a file and reading a file all show up in the launcher logs.

1 Like

You could set a breakpoint and examine the response object using the debugger.

I did, you can see the content of the response object in my reply a few post above. You won’t see functions though so it’s a bit hard to see what’s available and what is not. Anyway text() isn’t for some reason so if anyone else have a basic working example I could compare to see what I am doing wrong. There’s no rush though, this can wait for the official examples by @joshuef. Thanks for the help.

1 Like

Hmmm. Okay, I see the site now. And I’m facing the same problems with beaker’s sync at the moment too.

Not entirely sure where the problem lies, but I’m pretty sure it’s not with your code at this point.

Got to run to work now. I’ll dive in and get this straightened out this evening :thumbsup:

3 Likes