[OCG] Fix: capture app does not work in http hosts#5
[OCG] Fix: capture app does not work in http hosts#5nshandra wants to merge 4 commits intoversion-105.5.2-ocgfrom
Conversation
…ure context (http non localhost sites). Additionally allows to use the app in private mode.
tokland
left a comment
There was a problem hiding this comment.
Tested, it worked also for me. (It’s good to know that this was also the source of the issue with incognito windows!)
Just some minor implementation details:
| "@dhis2/d2-i18n": "^1.1.0", | ||
| "@dhis2/d2-ui-rich-text": "^7.4.0", | ||
| "@dhis2/rule-engine": "^3.4.1", | ||
| "@dhis2/rules-engine-javascript": "105.5.2", |
There was a problem hiding this comment.
It’s nice to have the entries sorted, but since this is a patching fork, I’d keep it as close to upstream as possible to make future merges easier.
There was a problem hiding this comment.
Done, package was auto sorted by yarn when i added js-sha256 but i see the point.
There was a problem hiding this comment.
Yep, yarn started doing this automatically at some version.
| return hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); | ||
| } catch (error) { | ||
| return sha256(input); | ||
| } |
There was a problem hiding this comment.
try/catch can mask other problems of the block.
What about using a conditional that checks if we have window.crypto.subtle?
There was a problem hiding this comment.
Try/catch seemed more "elegant" but its true it can mask other issues.
Changed and added a console.warn.
There was a problem hiding this comment.
Your point ("whatever goes wrong here, use this as a fallback") was also valid, so it's just about having more control when things go wrong.
References
Issue: [1348] Capture App - Try to install 102, 103 or 104
Description
Capture app does not work properly with non-localhost http hosts. When starting it only shows:
This was caused by the use of module
window.cryptoto generate a hash, but it only works in secure contexts.A exception handler was added to use a fallback library (js-sha256) in case the context is deemed not secure.
Incidentally this also allows the app to work in private/incognito mode.