Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose IPFS Core API as window.ipfs #42

Closed
flyingzumwalt opened this issue Feb 15, 2017 · 13 comments
Closed

Expose IPFS Core API as window.ipfs #42

flyingzumwalt opened this issue Feb 15, 2017 · 13 comments

Comments

@flyingzumwalt
Copy link
Contributor

flyingzumwalt commented Feb 15, 2017

Web Extension makes js-ipfs protocol (interface-core-api) available in the browser through window.ipfs

@flyingzumwalt flyingzumwalt removed the status/ready Ready to be worked label Feb 20, 2017
@haadcode haadcode added status/ready Ready to be worked status/in-progress In progress and removed status/ready Ready to be worked labels Feb 20, 2017
@haadcode
Copy link
Member

I did a quick prototype for this today: load js-ipfs packaged with the extension, start an instance.

Challenges here are similar to #41.

@haadcode
Copy link
Member

So basically as far as I can tell, the js-ipfs instance in the extension can't communicate to anyone except via https. Adding files, etc. would work normally, but an IPFS node without a network is fairly limited in functionality...

@victorb
Copy link
Member

victorb commented Feb 21, 2017

I got something working over here: https://github.com/VictorBjelkholm/js-ipfs-in-the-browser

Basically it sets up two parts. One background page for the daemon and handling communication with the content script. Two is the content script that injects functions to the page script.

You can download and install this: https://github.com/VictorBjelkholm/js-ipfs-in-the-browser/releases/tag/lol

When installed, this page should change from "nope" -> "yeah!" and also show your daemons id: https://ipfs.io/ipfs/QmcVc8eQiWkR23wMKiQjipLRSjCxR1FEj4TL99aY89J83d

@victorb victorb self-assigned this Feb 21, 2017
@haadcode
Copy link
Member

Great work @victorbjelkholm! 🎉

@victorb
Copy link
Member

victorb commented Feb 21, 2017

After standup call, I'll do the following before moving on:

  • Expose:
    • .cat
    • .add
    • .ls
    • .swarm.peers
    • .dag.put
    • .dag.get
    • .files.cat

@victorb
Copy link
Member

victorb commented Feb 21, 2017

@haadcode maybe you could list the methods you're using in Orbit, and we could get Orbit to work with the extension instance of js-ipfs? I'm betting the shipping JS without js-ipfs/js-ipfs-api would be minimal and load super fast!

@haadcode
Copy link
Member

@victorbjelkholm orbit is using .object.put/.get, .pubsub (pretty much all methods), .swarm.peers and .files.add/.cat. And the Electron version uses those + .util.addFromFs and .ls.

@flyingzumwalt
Copy link
Contributor Author

Can I add a request that we document how to get at the other API methods? For example, if I want to use ipfs.dht.findProvs but it hasn't been added by the web extension, how can I connect to ipfs and consume that API method? What libraries do I need to download? Do I need to initialize a separate connection to the ipfs daemon? etc...

@victorb
Copy link
Member

victorb commented Feb 23, 2017

So, trouble in wonderland. Seemingly, you cannot pass functions or anything that can't be serialized into JSON between the background and content scripts.

This makes the interface of for example .cat to be broken, since we would only be able to pass the finalized data rather than a stream with the data...

Not sure how to solve this, but reached out in Mozilla IRC about confirmation and help with workarounds if possible.

Reference: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/sendMessage

message any. An object that can be serialized to JSON.

@Kubuxu
Copy link
Member

Kubuxu commented Feb 23, 2017

@victorbjelkholm it is intended behaviour as the background and content scripts might run in separate JS engine instances.

@ghost ghost added status/ready Ready to be worked and removed status/in-progress In progress labels Mar 28, 2017
@ghost ghost changed the title WebExtension makes full **js-ipfs** core api (interface-core-api) available in the browser Expose Core API to content pages Apr 18, 2017
@ghost
Copy link

ghost commented Apr 18, 2017

Probably the next steps here are:

Edit, also:

  • Make "big" Core API requests/responses work over the limited background page messaging, i.e. chunk them.

@ghost ghost changed the title Expose Core API to content pages Expose IPFS Core API to content pages Apr 18, 2017
@ghost ghost changed the title Expose IPFS Core API to content pages Expose IPFS Core API as window.ipfs Apr 18, 2017
@ghost ghost added the developers label Apr 18, 2017
@lidel
Copy link
Member

lidel commented Jan 2, 2018

FYSA we hope to deliver this feature via browser extension (it will be an opt-in experiment initially)
Implementation progress can be tracked in ipfs/ipfs-companion#330

@lidel
Copy link
Member

lidel commented Mar 6, 2018

This feature landed in Beta channel of our browser extension.
Check Release Notes for v2.2.0beta2 and Notes on exposing IPFS API as window.ipfs.

Discussion related to window.ipfs continues in ipfs/ipfs-companion#330

@lidel lidel closed this as completed Mar 6, 2018
@ghost ghost removed the status/ready Ready to be worked label Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants