paho.mqtt.javascript
paho.mqtt.javascript copied to clipboard
access denied error thrown when cookies disabled
Environment: Chrome browser on MacOS
Reproduce Steps
- In incognito window mode of chrome browser
- toggle "disable cookies" button
- try loading the script , it fails accessing localStorage since the localStorage property exists but access is restricted
the handling in the current code is checking if property exists instead it should gracefully handle it by catching the exception and polyfill it.
Error Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document
It appears this happens even if you don't change the cookie settings. I'm wondering if Chrome made localstorage access more strict in a recent update. This is actually breaking our application in production.
This is the culprit: https://github.com/eclipse/paho.mqtt.javascript/blob/f5859463aba9a9b7c19f99ab7c4849a723f8d832/src/paho-mqtt.js#L109
That needs to be wrapped in a try/catch and gracefully handled.