js-ipfs
js-ipfs copied to clipboard
Uncaught SecurityError: Failed to execute 'open' on 'IDBFactory'
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;
}
});
});
}
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?
ping @LeonFangCN
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
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.
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.
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.