paho.mqtt.javascript
paho.mqtt.javascript copied to clipboard
localStorage issue in Chrome extension
Chrome extension does not support window.localStorage, and If you try to use the library to build an extension for Chrome you run into error window.localStorage is not available in packaged apps. Use chrome.storage.local instead. Quick fix for that is basically assign chrome.storage.local to
window.localStorage window.localStorage = chrome.storage.local; before create client, also to make it work you need to add storage permission to a manifest file.
I'd prefer to not browser specific changes into the client itself, especially for non-standard use. I'll add a section to the readme though to outline the solution you found as I think that's probably the best resolution for this issue. Thanks for letting us know!
PR https://github.com/eclipse/paho.mqtt.javascript/pull/158 would set up the utility be being able to run as chrome app (including tcp/tls). The error still shows once, because it is triggered on every read request to window.localStorage (even the one used for testing for === undefined). The chrome apps would still need a nice icon, though