Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Uncaught Error : Callback was already called(exchange-files-in-browser) #2153

Closed
hapsody opened this issue Jun 4, 2019 · 5 comments · Fixed by #2211
Closed

Uncaught Error : Callback was already called(exchange-files-in-browser) #2153

hapsody opened this issue Jun 4, 2019 · 5 comments · Fixed by #2211

Comments

@hapsody
Copy link
Contributor

hapsody commented Jun 4, 2019

  • Version:
    js-ipfs version: 0.36.2-
    Repo version: 7
    System version: x64/darwin
    Node.js version: v11.10.1

  • Platform:
    Darwin neojuneui-MacBook-Pro-146.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
    Chrome 74.0.3729.169 (official build) 64-bit

  • Subsystem:
    Maybe, it's about libp2p, if I'm correct.

Type: Question

Severity: High

Description:

Exchange-files-in-browser example doensn't work except case in localhost

Steps to reproduce the error:

I've checked a guide right below. It seems to be a perfect guide to me on the same machine.
https://github.com/ipfs/js-ipfs/tree/master/examples/exchange-files-in-browser

But If I tried to download a file on another machine. I got an error message from browser trying to connect
(A computer in the same local network. for example, A server node sharing a file is 192.168.0.22. request node trying to download the file is 192.168.0.33)
스크린샷 2019-06-03 오후 8 56 06

Error Message

[Jun 3, 06:11:35 pm] [contentScript]: [INFO]: Initialising TronLink
contentScript.js:2146 [Jun 3, 06:11:35 pm] [contentScript]: [INFO]: TronLink injected
3pageHook.js:38572 [Jun 3, 06:11:35 pm] [ProxiedProvider]: [INFO]: Provider initialised
3pageHook.js:38572 [Jun 3, 06:11:35 pm] [ProxiedProvider]: [INFO]: Received new node: https://api.trongrid.io
pageHook.js:38572 [Jun 3, 06:11:35 pm] [pageHook]: [INFO]: TronLink initiated
bundle.js:55459 Uncaught TypeError: Cannot read property 'generateKey' of undefined
at Object.exports.generateKey (bundle.js:55459)
at Object.generateKeyPair (bundle.js:55757)
at Object.exports.generateKeyPair (bundle.js:55219)
at bundle.js:101414
at nextTask (bundle.js:15583)
at exports.default (bundle.js:15593)
at Function.exports.create (bundle.js:101413)
at bundle.js:127522
at nextTask (bundle.js:15583)
at next (bundle.js:15590)
bundle.js:14046 Uncaught Error: Callback was already called.
at bundle.js:14046
at bundle.js:30301
at bundle.js:52749
at bundle.js:31733
at IDBTransaction.tx.onabort (bundle.js:51676)

@hapsody hapsody changed the title js-ipfs example (exchange-files-in-browser) doesn't work except case in localhost Uncaught Error : Callback was already called(exchange-files-in-browser Jun 4, 2019
@hapsody hapsody changed the title Uncaught Error : Callback was already called(exchange-files-in-browser Uncaught Error : Callback was already called(exchange-files-in-browser) Jun 4, 2019
@dirkmc
Copy link
Contributor

dirkmc commented Jun 4, 2019

@hapsody thanks for the bug report. I believe this is due to a restriction with WebCrypto where it will not load in a page unless that page is loaded over https, or the page is served from localhost: libp2p/js-libp2p-crypto#105

I guess the solution is that we should update the example to include a warning about this restriction. Would you be interested in opening a PR to do so?

@hapsody
Copy link
Contributor Author

hapsody commented Jun 5, 2019

@dirkmc Thank you for your reply.

You mean that it's a known problem about libp2p/js-libp2p-crypto#105 not solved yet? so we can only change the guide yet. Do I understand correctly?

I don't know exactly about a sort of PR thing since I'm a newbie for opensource process.
Is there anything that I can help? If there is, I'd like to help.

@dirkmc
Copy link
Contributor

dirkmc commented Jun 6, 2019

@hapsody that's correct, it's a known issue.

If you would like to contribute a PR we would appreciate it.

To create a PR against this project, you can

  1. Fork the project to your local github account
  2. Clone the fork locally
  3. Create a new branch, eg git checkout -b fix/examples-exchange-files-in-browser-docs
  4. Make your changes
  5. Commit your change, eg git commit -m "fix: exchange-files-in-browser documentation"
  6. Push to your branch
  7. Open a PR from your fork to ipfs/js-ipfs

@hapsody
Copy link
Contributor Author

hapsody commented Jun 7, 2019

I think "PR" means "Pull Request"
Thanks for the details! I'll try it and reply.

@dirkmc
Copy link
Contributor

dirkmc commented Jun 7, 2019

Yes PR means Pull Request, you can find more information here:
https://help.github.com/en/articles/creating-a-pull-request-from-a-fork
Thanks for taking the time to contribute!

hapsody added a commit to hapsody/js-ipfs that referenced this issue Jul 2, 2019
This example doesn't work except the case in localhost ( related to ipfs#2153)
This is known because of a restriction with WebCrypto (libp2p/js-libp2p-crypto#105)
I add a explanation of a example's restriction to run
alanshaw pushed a commit to libp2p/js-libp2p-crypto that referenced this issue Jul 4, 2019
This PR adds `crypto-browserify` to the dependencies and replaces `crypto` with `crypto-browserify` when bundled in the browser.

In files that require webcrypto we check to see if it's available. If it is not we require the Node.js implementation (which has `crypto` replaced with `crypto-browserify`) and if it is available then we use the webcrypto version (so we get fast crypto).

Shipping `crypto-browserify` adds to the bundle size:

Current gzipped size: 142,824 bytes
New gzipped size: 214,499 bytes

Difference: **+71,675 bytes**

It's not an insignificant addition so we need to decide whether this is worth it.

If not accepted, we need to add checks when libp2p-crypto methods are called and callback with an appropriate error message. JS IPFS will continue to have issues opened with confusion around this otherwise! See ipfs/js-ipfs#963 ipfs/js-ipfs#964 ipfs/js-ipfs#2153

resolves #105

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw pushed a commit that referenced this issue Jul 4, 2019
This example doesn't work except the case in localhost ( related to #2153)
This is known because of a restriction with WebCrypto (libp2p/js-libp2p-crypto#105)
I add a explanation of a example's restriction to run
alanshaw pushed a commit to libp2p/js-libp2p-crypto that referenced this issue Jul 9, 2019
Changes `webcrypto.js` to check for native web crypto availability and falls
back to using `window.__crypto` if not available.

If the user wants to bring their own Web Crypto API compatible implementation
then they simply need to assign it to `window.__crypto` before they start using
IPFS.

Checks are done in the functions that require web crypto to give the user the
flexibility to assign to `window.__crypto` before OR after they import
`libp2p-crypto`. It also means that users have the ability to use other exported
functions that do not require web crypto without having to worry about sorting
their own implementation.

We use `window.__crypto` because `window.crypto` is a readonly property in
secure context and always readonly in workers.

If `window.crypto` and `window.__cypto` are unavailable then an appropriate
error message is reported to the user with a `ERR_MISSING_WEB_CRYPTO` code.

I've also added documentation to the README.

This is a backwards compatible change.

closes #149
resolves #105
resolves ipfs/js-ipfs#2017
resolves ipfs/js-ipfs#2153

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw added a commit to libp2p/js-libp2p-crypto that referenced this issue Jul 17, 2019
This PR simply detects missing web crypto and throws an error with an appropriate message.

This is a stepping stone that will help users understand the problem until we have time to do a refactor of this module and of all the modules that use it to enable optionally passing your own crypto implementation.

refs #149
refs #150
refs #105
refs ipfs/js-ipfs#2153
refs ipfs/js-ipfs#2017

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
jacobheun pushed a commit to libp2p/js-libp2p-crypto that referenced this issue Jul 22, 2019
This PR simply detects missing web crypto and throws an error with an appropriate message.

This is a stepping stone that will help users understand the problem until we have time to do a refactor of this module and of all the modules that use it to enable optionally passing your own crypto implementation.

refs #149
refs #150
refs #105
refs ipfs/js-ipfs#2153
refs ipfs/js-ipfs#2017

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
Mikerah pushed a commit to ChainSafe/js-libp2p-crypto that referenced this issue Aug 29, 2019
This PR simply detects missing web crypto and throws an error with an appropriate message.

This is a stepping stone that will help users understand the problem until we have time to do a refactor of this module and of all the modules that use it to enable optionally passing your own crypto implementation.

refs libp2p#149
refs libp2p#150
refs libp2p#105
refs ipfs/js-ipfs#2153
refs ipfs/js-ipfs#2017

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
oliveriosousa pushed a commit to ipfs-examples/js-ipfs-examples that referenced this issue Jul 26, 2021
This example doesn't work except the case in localhost ( related to ipfs/js-ipfs#2153)
This is known because of a restriction with WebCrypto (libp2p/js-libp2p-crypto#105)
I add a explanation of a example's restriction to run
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants