ready() promises do not resolve in a mobile context when using browserified dat-sdk
See original GitHub issueThe following html works in a desktop browser, but does not on the mobile browsers I tried (Safari, Brave).
The drive.ready()
does not resolve, it appears.
<!DOCTYPE html><html>
<head>
<script src="lib/dat-sdk-bundle.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head><body>
<script>
let hypersdk
let drive
let core
// Runs through initialisation of hyper core and hyperdrive, puts status messages in html doc.
;(async function(){
await new Promise(resolve => document.addEventListener('DOMContentLoaded', resolve));
document.getElementById('setup').innerHTML += 'dom loaded<br>'
hypersdk = await window.datSDK();
document.getElementById('setup').innerHTML += 'hypersdk loaded<br>'
drive = await hypersdk.Hyperdrive('drive')
document.getElementById('drive').innerHTML += 'drive created<br>' //+String(drive.ready()) Note adding this shows that mobile browser recognises ready() as promise obj
await drive.ready()
document.getElementById('drive').innerHTML += 'drive ready<br>'
document.getElementById('drive').innerHTML += 'drive key = ' + drive.key.toString('hex') +'<br>'
core = await hypersdk.Hypercore('core')
document.getElementById('core').innerHTML += 'core created<br>' +String(core.ready())
await core.ready()
document.getElementById('core').innerHTML += 'core ready<br>'
document.getElementById('core').innerHTML += 'core key = ' + core.key.toString('hex') +'<br>'
})();
</script>
<!-- main container div -->
<div id="main" style="width:100%;height:auto;display:grid;grid-template: auto auto auto/ auto;background-color:red;">
<div id="setup" style="width:100%;height:auto;grid-area: 1 / 1 / 2 / 2;;background-color:lavender;">
INIT:<br>
</div>
<div id="drive" style="width:100%;height:auto;grid-area: 2 / 1 / 3 / 2;transition: all 0.5s;background-color:lightgreen;">
DRIVE:<br>
</div>
<div id="core" style="width:100%;height:auto;grid-area: 3 / 1 / 4 / 2;transition: all 0.5s;background-color:yellow;">
CORE:<br>
</div>
</div>
</body></html>
Thanks for creating this great library!
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Promise will not resolve - Stack Overflow
You need to resolve a promise by calling one of the functions it provides in the callback through its constructor. const promise =...
Read more >browserify/browserify: browser-side require() the node.js way
Use a node-style require() to organize your browser code and load modules installed by npm. browserify will recursively analyze all the require() calls...
Read more >Browserify
Browserify lets you require('modules') in the browser by bundling up all of your dependencies. Install Documentation · Source Code · Help + Articles...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The SDK has changed a bunch since this happened, so it may be working again.
hmmm, error has gone but promise still does not resolve 🤔