oasis icon indicating copy to clipboard operation
oasis copied to clipboard

Turn oasis into a browser extension

Open Powersource opened this issue 4 years ago • 20 comments

Now this title isn't saying Please do this, it's saying I want to try to do this, it's fine if you ignore any eventual PR/changes, although collaboration would make this easier and would be appreciated

I think this would be super cool, we could have a purely browser-extension p2p client (not counting pubs), I don't think there are many of those in the world (e.g. metamask uses a centralized server; that dat thing tunnels all traffic through a specific server as well).

2 simple (lol) steps needed:

  • [ ] 1. Make all the logic of oasis run in the browser. Put another way, a statically hosted website. I saw that you maybe had some plan for that with choo @christianbundy ? This would also be the part where we switch to using https://github.com/arj03/ssb-browser-core/ for the ssb db, networking and so on :D In this step we hopefully also don't completely break the security when changing around the CSP settings :sweat_smile:
  • [ ] 2. Move it all into a browser extension. This should be the easy step.

Any thoughts/help/etc appreciated :) Especially with oasis's inner workings, which I'm not familiar with so far.

@georgeowell @arj03

Powersource avatar Feb 06 '20 17:02 Powersource

I don't know how easy it would be to use choo, since it doesn't support async routes/rendering and oasis seems to use that a lot.

Powersource avatar Feb 06 '20 19:02 Powersource

@soapdog would it be a good idea to try this in patchfox instead? Or how stable/in flux is it? :grimacing:

Powersource avatar Feb 06 '20 20:02 Powersource

Browser extensions can't run on special pages made by other browser extensions. So I can't use these things with Patchfox: my Vim keyboard shortcuts, CSS customization extensions, etc.

Is it possible to run a full localhost webserver in an extension so the pages will be normal localhost pages and not, like, moz-extension://...?

I ask this not in opposition, just thinking ahead.

cinnamon-bun avatar Feb 06 '20 21:02 cinnamon-bun

You can't run a webserver on an extension. There is no way to bundle the server code. You can however launch a local program, which could be a server. That's how the initial version of Patchfox was able to start Scuttle Shell on its own. This uses the Native Messaging API. So you could have a minimal add-on that start a compiled Oasis server if you want. The user will need a separate procedure to install this native server, add-ons can't install native apps.

soapdog avatar Feb 06 '20 22:02 soapdog

@Powersource is cool and valid... but this issue is not :smile:

georgeowell avatar Feb 07 '20 16:02 georgeowell

To clarify, I'm not saying anyone should turn oasis into a browser extension (although I wouldn't mind because I think it would be pretty cool). I just want to try to put a scuttlebutt client into a browser extension and have it run there without connecting to some local ssb-server (i.e. using ssb-browser-core instead). And I thought maybe the best way of doing that was with oasis. But idk, it looks like a pretty big effort to do it with oasis atm so I might just do it with the ssb-browser-demo instead.

Powersource avatar Feb 07 '20 17:02 Powersource

I'll be happy to help how I can. I was waiting for Christian to chime in, but it appears he is sick.

The security model aspect is interesting. I actually was not aware of that when browsing this project, maybe it should be more front and center as its actually a pretty nice selling point for some people. Disabling JS is not going to work if you run SSB in the same tab, but I'm wondering if running ssb-browser-core as a browser extension might work. And then run oasis as normal.

arj03 avatar Feb 07 '20 19:02 arj03

if running ssb-browser-core as a browser extension might work. And then run oasis as normal.

I'm guessing it wouldn't since like soapdog says, "You can't run a webserver on an extension". Or maybe there's some other way for them to connect?

on a similar topic, @soapdog how well do the custom protocol handlers work nowadays? Could we maybe have the user on ssb:/feed/something instead of moz-extension://..., and would that let us use stuff like vimium on the pages?

Powersource avatar Feb 07 '20 20:02 Powersource

Meta-note: In my mind, the 'invalid' label is usually for when you open an issue in the wrong repository, open a pull request into the wrong branch, or some other "oops". I think there might be some semantic conflicts around this label, so I'd like to suggest that we don't use it until/unless we iron those out. :heart:

christianbundy avatar Feb 08 '20 00:02 christianbundy

I'm probably not going to be :100: for a few days so I'll probably give this some more thought when I'm feeling better, but quick notes:

  • It would be cool to make Oasis run on something like HTTP-SPA (please some other well-supported implementation though) so it isn't paired to the Node.js HTTP dependency. Right now my priority is making sure that Oasis can support migration from Patchwork but this would be nice.
  • Big +1 to making sure that Oasis can be browserified in the future. A browser extension would be a really interesting distribution format that I'd love to see others experiment with.
  • I'm very appreciative that I'm friends with literally the most prominent experts in building a full SSB node in the browser and packaging an SSB client in a browser extension. What a time to be alive.

christianbundy avatar Feb 08 '20 01:02 christianbundy

To clarify, I'm not saying anyone should turn oasis into a browser extension (although I wouldn't mind because I think it would be pretty cool). I just want to try to put a scuttlebutt client into a browser extension and have it run there without connecting to some local ssb-server (i.e. using ssb-browser-core instead).

@Powersource it should be easy to do that with Oasis as long as you're connecting to an externally running ssb-server which is exactly how Patchfox work.

The only ticky part is browserifying the client. You can't really rollup/webpack it as there are dependencies which don't run in strict mode and at least rollup will refuse to compile.

You'd need some sort of shim or very thin JS to act as the router and decide which view to send. I don't know how those views are built, but if this little shim could build them then it should work.

A minimal version would need:

  • a manifest.json declaring a pageAction (aka a button in the toolbar).
  • some client-side router and a way to run Oasis templating.
  • browserified (or if you can sort webpack) blob with ssb-client and whatever other nodejs stuff you need.

soapdog avatar Feb 08 '20 11:02 soapdog

on a similar topic, @soapdog how well do the custom protocol handlers work nowadays? Could we maybe have the user on ssb:/feed/something instead of moz-extension://..., and would that let us use stuff like vimium on the pages?

@Powersource I think that mozilla changed something in Firefox because all my ssb:<hash> have been failing for a while. TBH they were never valid URLs, so changing something maybe Mozilla means just fixed something. We can't agree on a real URL conformant scheme in the community. The best current option is ssb-uri by @christianbundy which I want to support, I remember there being a bug that prevented me from browserifying it, some access to fs.* in the source, so I couldn't use it in Patchfox.

Still, even with real URLs we can't have them appear in the URL of Firefox as ssb:. As soon as the add-on takes over, it changes the URLs as custom URLs are actually redirects to internal add-on pages. Libdweb had a way around it but it is quite dead.

soapdog avatar Feb 08 '20 11:02 soapdog

So I started on a fork of ssb-browser-demo. It's technically a browser extension now, but nothing works since I think the js doesn't run or something hehe https://github.com/Powersource/ssb-webextension-demo/pull/1

image

Powersource avatar Feb 10 '20 23:02 Powersource

@Powersource Nice! I'll look forward to updates on your project.

Anything I can do to close this issue?

christianbundy avatar Feb 12 '20 19:02 christianbundy

I think it's fine to close this issue (if you want to minimize open issues), as long as it isn't locked, so we can possibly continue discussion :)

Powersource avatar Feb 15 '20 16:02 Powersource

booyakasha https://addons.mozilla.org/en-US/firefox/addon/ssb-webextension-demo/

Powersource avatar Feb 16 '20 17:02 Powersource

WOOP WOOP. I don't want to close this issue because it's something you're working on, maybe we could transfer it to your repo? If you add me as a collaborator on your project I think that'll let me do it? Not 100% sure.

christianbundy avatar Feb 18 '20 19:02 christianbundy

booyakasha https://addons.mozilla.org/en-US/firefox/addon/ssb-webextension-demo/

one of us! one of us! one of us!

soapdog avatar Feb 19 '20 10:02 soapdog

@christianbundy I don't have any code on this for oasis, only done the browser-demo one so far. Would maybe be keen on helping you with http-spa and getting that into oasis, as a first step (if that's something you want).

Powersource avatar Feb 20 '20 22:02 Powersource

I'm super interested in figuring out a way to do routing that's engine-agnostic and doesn't require Node.js, but HTTP-SPA is so hacky and prototypy that I'd really like to avoid using it in production. My guess is that the best way to do this would be to copy the shape of an existing router, either Express or Koa or something, and make a browserify-able variant, but honestly at that point I'm thinking we might as well just write Oasis in a language that compiles to WASM or something.

:man_shrugging:

I think this is too far in the future to be actionable for me, personally.

christianbundy avatar Mar 24 '20 16:03 christianbundy