js-ipfs icon indicating copy to clipboard operation
js-ipfs copied to clipboard

Uncaught SecurityError: Failed to execute 'open' on 'IDBFactory'

Open LeonFangCN opened this issue 4 years ago • 5 comments

I/chromium(18209): [INFO:CONSOLE(1)] "Invalid asm.js: Unexpected token", source: https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js (1) I/chromium(18209): [INFO:CONSOLE(1)] "Uncaught SecurityError: Failed to execute 'open' on 'IDBFactory': access to the Indexed Database API is denied in this context.", source: https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js (1)

js code

  function getIPFS(){
    var node = new Ipfs();
    node.on('ready', () => {
      node.id(function (err, res) {
        if (err) {
        } else {
          document.getElementById("ipfs").innerHTML=res.id;
        }
      });
    });
  }

LeonFangCN avatar Jul 16 '19 03:07 LeonFangCN

What browser are you using @LeonFangCN? Would you mind trying again with https://cdn.jsdelivr.net/npm/ipfs/dist/index.js so we get a better stack trace?

alanshaw avatar Jul 16 '19 13:07 alanshaw

ping @LeonFangCN

alanshaw avatar Jul 22 '19 08:07 alanshaw

I/chromium( 3972): [INFO:CONSOLE(144817)] "Uncaught SecurityError: Failed to execute 'open' on 'IDBFactory': access to the Indexed Database API is denied in this context.", source: https://cdn.jsdelivr.net/npm/ipfs/dist/index.js (144817)

android webview

@alanshaw

LeonFangCN avatar Jul 22 '19 11:07 LeonFangCN

What browser are you using @LeonFangCN? Would you mind trying again with https://cdn.jsdelivr.net/npm/ipfs/dist/index.js so we get a better stack trace?

I am using the official webview_flutter package from Flutter to open a WebView in Android to run the IPFS node. I am having the same problem.

Hamza5 avatar Jan 05 '22 21:01 Hamza5

I came here again because I think that I have found a workaround.

Chromium-based browsers (like Android WebView) do not allow access to LocalStorage (which is used by IPFS) from a webpage hosted locally. So, you have to make your script load from a webpage accessed through a remote-file protocol, like HTTP/HTTPS for example.

However, you can easily trick Chromium by loading a random empty webpage through HTTP/HTTPS (I use https://www.blank.org/), then load the source of the ipfs.min.js and evaluate in the WebView. In this way, Chromium will not trigger its crazy security policy, because it thinks that the script was loaded with the page.

Hamza5 avatar Jan 06 '22 09:01 Hamza5

js-ipfs is being deprecated in favor of Helia. You can learn more about this deprecation and read the migration guide.

Please feel to reopen with any comments by 2023-06-02. We will do a final pass on reopened issues afterwards (see https://github.com/ipfs/js-ipfs/issues/4336).

Thanks for the update and explanation for users experiencing this issue @Hamza5.

SgtPooki avatar May 26 '23 17:05 SgtPooki