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

How to use in Browser? #70

Open
klues opened this issue Nov 28, 2018 · 8 comments
Open

How to use in Browser? #70

klues opened this issue Nov 28, 2018 · 8 comments

Comments

@klues
Copy link

klues commented Nov 28, 2018

The provided link in the readme:
the browserified version from wzrd.in
is dead.

So how could I get crypto-pouch running in a browser? Is there any other place to get a compiled js-file that can be used in browsers?

@kiyanovsky
Copy link

I use it the following way in my extension:

import CryptoPouch from 'crypto-pouch'
PouchDB.plugin(CryptoPouch);

and then

db.crypto(password)

@tibomogul
Copy link

The link is dead, where else can we get the browserified version?

@garbados
Copy link
Collaborator

garbados commented Aug 6, 2021

At this time, we don't distribute browserified versions of crypto-pouch. That may change soon, though! In the meantime, you're best off creating your own, like this:

$ curl https://unpkg.com/[email protected]/index.js > crypto-pouch-original.js
$ npx browserify crypto-pouch-original.js -o crypto-pouch.js

Now you can include crypto-pouch.js in your projects with a <script> tag:

<script src="crypto-pouch.js" charset="utf-8"></script>

Let me know if that works for you :)

I'll leave this issue open until we distribute a browserified version ourselves.

@t0PPy
Copy link

t0PPy commented Nov 18, 2022

Hey,

I'm struggeling to get crypto-pouch working in the browser. I tried the steps above and they didn't work.

First I had to do a npm add crypto-pouch before doing the browserfy (makes sense it needs it's dependencies there).

But even after that it fails in the browser with: "Invalid plugin: got "[object Object]", expected an object or a function"

It basically seems to fail when the plugin is being added to pouch:

if (typeof window !== 'undefined' && window.PouchDB) {
window.PouchDB.plugin(exports)
}

Hopefully someone can advice on how to get this running!

Best,
Olav

@setop
Copy link

setop commented Nov 29, 2023

it fails in the browser with: "Invalid plugin: got "[object Object]", expected an object or a function"

same here.

any advice on how to workaround this ?

@garbados
Copy link
Collaborator

Hey folks. I'm unable to reproduce this issue based on the info provided. If you can provide more info about your setup, I can try reproducing this again. Until then, this works on my end:

const CryptoPouch = require('crypto-pouch')
const PouchDB = require('pouchdb')
PouchDB.plugin(CryptoPouch)

const db = new PouchDB("test")

db.crypto("hello world")
  .then(() => console.log("encrypted!"))
  .then(() => db.post({hello: "world"}))
  .then(({ id }) => console.log(id))

This prints:

encrypted!
f261a66f-df0d-49c5-9a8c-e071a59bc0c7

When reporting issues, please supply:

  • Your PouchDB version.
  • How you bundle PouchDB and Crypto-Pouch.

For my part, I tried with PouchDB v7.2.2 and v8.0.1.

@setop
Copy link

setop commented Nov 30, 2023

I tried to "browserify" crypto-pouch and garbados-crypt, then import in an a html plas using a <script> tag.
And get the error.

@garbados
Copy link
Collaborator

garbados commented Dec 7, 2023

I tried to "browserify" crypto-pouch and garbados-crypt, then import in an a html plas using a <script> tag. And get the error.

You shouldn't need to browserify these things directly. Browserify the entry point of your program -- where you require these things, where your app starts. That will automatically bring in dependencies. Otherwise, IIRC, Browserify wraps these dependencies so they aren't available in a global context, as your setup requires.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants