paho.mqtt.javascript icon indicating copy to clipboard operation
paho.mqtt.javascript copied to clipboard

access denied error thrown when cookies disabled

Open bpcrao opened this issue 4 years ago • 1 comments

Environment: Chrome browser on MacOS

Reproduce Steps

  1. In incognito window mode of chrome browser
  2. toggle "disable cookies" button
  3. 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

bpcrao avatar Sep 22 '21 17:09 bpcrao

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.

ffxsam avatar Nov 08 '21 17:11 ffxsam