oliverfindl / vue-svg-inline-plugin

Vue plugin for inline replacement of SVG images with actual content of SVG files.
MIT License
33 stars 3 forks source link

Crashes in incognito when iframed #13

Closed hognevevle closed 2 years ago

hognevevle commented 2 years ago

Hi there,

My application which uses vue-svg-inline-plugin is being served via an iframe. Unfortunately, this crashes the app when the user's browser is running in incognito/private mode.

Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    at Object.install (webpack-internal:///./node_modules/vue-svg-inline-plugin/src/index.js:222:71)
    at Object.use (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:3957:28)
[...]

Unfortunately, setting cache.persistent to false does not help. Is there another way to completely disable the use of localstorage?

hognevevle commented 2 years ago

Update: also setting cache.removeRevisions to false fixed the error 🥳

oliverfindl commented 2 years ago

Hello,

honestly I don't know why is it crashing, because there is already check for local storage availability.

https://github.com/oliverfindl/vue-svg-inline-plugin/blob/63566067340121503b46a6d66faac4be3742487a/src/index.js#L206

More so, every action with local storage is conditioned with this check and (options.cache.persistentor options.cache.removeRevisions) option. Therefore, if both options are set to false, there should be no local storage action even if my initial check is somehow failing in case of combination incognito/private window and iframe.

https://github.com/oliverfindl/vue-svg-inline-plugin/blob/63566067340121503b46a6d66faac4be3742487a/src/index.js#L211

https://github.com/oliverfindl/vue-svg-inline-plugin/blob/63566067340121503b46a6d66faac4be3742487a/src/index.js#L217

https://github.com/oliverfindl/vue-svg-inline-plugin/blob/63566067340121503b46a6d66faac4be3742487a/src/index.js#L220

https://github.com/oliverfindl/vue-svg-inline-plugin/blob/63566067340121503b46a6d66faac4be3742487a/src/index.js#L499

Probably this check is not sufficient for your use case, but I can not check it automatically by setting and getting a value, because this check would violate law in my country (access to user storage without user consent).

Additionally, error in your post tracks to line 222, which is line with comment only...

https://github.com/oliverfindl/vue-svg-inline-plugin/blob/63566067340121503b46a6d66faac4be3742487a/src/index.js#L222

Well, I'm glad you solved this issue yourself by setting both options to false.

Thanks.