I know this is a rather basic question, but I can’t seem to easily figure it out. A bit of background on my configuration first: I downloaded go-ipfs from which I run the IPFS daemon, my operating system is Linux openSUSE Tumbleweed 64bit, and my web browser is Firefox 57.
I plan to attempt coding a website for IPFS, which will make use of the js-ipfs API for IPFS related JavaScript functions. I don’t understand how to get this API working in Firefox: The IPFS daemon is a separate process running in the background, I doubt it can serve Firefox with information about new JavaScript functions. Do I need an addon in Firefox, or do I simply have to reference the external library in my scripts using a line of code (similarly to #include statements in other languages)?
The instructions I found so far seem to be for system wide JavaScript, as they involve “npm install” which has nothing to do with Firefox as far as I know. I just need the browser itself to understand the IPFS JavaScript API when interpreting scripts on websites.
If you don’t want to run entire node in JS, you can use js-ipfs-api to interact with go-ipfs running on your machine (perfectly fine for prototyping). This happens over HTTP API. There is a browser bundle that works in Firefox. See docs for running it in a web browser from CDN.
You can also build your own bundle using browserify of webpack – check examples.
TL;DRjs-ipfs-api should be enough to give you window.ipfs object that exposes IPFS API to start coding against.
Shipping: remote node + js-ipfs-api OR js-ipfs
If you want to ship something that does not require locally/remotely running go-ipfs, you can use real js-ipfs. It can be a drop-in replacement for js-ipfs-api. Examples.
Future Optimizations of window.ipfs
In the future, our browser extension will provide an opt-in to expose IPFS API of your local node under window.ipfs on all websites. Your web app will be able to detect if it already exists and re-use it instead of spawning own js-ipfs node. This is work-in-progress and is tracked at ipfs-companion/issues/330.
(Mentioning it here so that you can already plan for this and add check for existence of window.ipfs)
(Deep Future Optimizations)
Your web browser will expose window.ipfs out-of-the-box
Hmmm… thanks for the info. That’s quite a bit more complicated than what I had hoped for. Perhaps there will be a browser with native IPFS support which will also contain its JavaScript API? Or maybe the IPFS Companion extension may come with an implementation for it in the future as well?