Option to disable local storage usage?

502 views
Skip to first unread message

sbi

unread,
Aug 15, 2019, 5:17:39 AM8/15/19
to PDFTron WebViewer
Hello,

we are using the WebViewer in such a way that the sources are hosted on a different domain than the one that is displaying the WebViewer.
This works fine in normal use cases but prevents the WebViewer from loading when the user disabled third party cookies in their browser settings.

As the cause of this issue we identified that the WebViewer saves and loads some preferences of the current user in the local storage of the browser which also counts as third party cookies violation when accessed from a different domain.
These settings stored by the WebViewer seem to be the color and options inside the annotation tools.

As most users actually never see the annotation tools and even if these settings are not really necessary we would like to disable the access of local storage by the WebViewer entirely as this would highly improve the usability for some users and minimize support effort on our end.

Is this possible or could a setting for this be added to the next WebViewer release?

Andrew Yip

unread,
Aug 15, 2019, 7:47:33 PM8/15/19
to PDFTron WebViewer
Hi,

Thank you for the detailed description of the problem, it helped a lot. We have a 'disableLocalStorage' ( https://www.pdftron.com/api/web/WebViewer.html#disableLocalStorage__anchor ) method you can use to keep WebViewer from setting the local storage but it seems your issue might be on load rather then when styles changed. I was able to reproduce this problem and made a fix for it in the link below
https://pdftron.s3.amazonaws.com/custom/ID-zJWLuhTffd3c/WebViewer/WebViewer_5.2.0.72203_CORSFix.zip

This will be added to our nightly build soon. Please let me know if it works for you or if you have any other questions

Best Regards,

Andrew Yip
Software Developer
PDFTron Systems, Inc.

sbi

unread,
Aug 16, 2019, 3:00:51 AM8/16/19
to PDFTron WebViewer
Hi Andrew,

thanks for the fast response and fix for this issue. We will test this as soon as possible

sbi

unread,
Sep 5, 2019, 9:58:18 AM9/5/19
to PDFTron WebViewer
Hi Andrew,

i tested the proposed solution and it seems to work as in the viewer loads even when third party cookies are blocked in the browser.
What does not seem to work / make a difference is setting the disableLocalStorage option after the viewer is loaded.
We would prefer this as the current solution still writes to the localstore even when the option is set and outputs some warnings in the console when third party cookies are blocked.

Did I set the option wrong or could you take another look at it? Thanks!


Am Freitag, 16. August 2019 01:47:33 UTC+2 schrieb Andrew Yip:

Andrew Yip

unread,
Sep 5, 2019, 3:09:44 PM9/5/19
to pdfnet-w...@googlegroups.com
Hi,

I want to confirm that you're calling 'disableLocalStorage()' correctly. Since your "lib" folder is in another domain, you'll need to call 'disableLocalStorage' either in a 'config' file or using postMessageAPI. You can find more in the link below
https://www.pdftron.com/documentation/web/guides/wv-inside/#loading-webviewer-from-another-domain

Please let me know if the above helps or if you have other questions

sbi

unread,
Sep 5, 2019, 4:40:00 PM9/5/19
to PDFTron WebViewer
Hi Andrew,

yes the two methods i tried were adding the disableLocalStore call to the then of the WebViewer constructor promise and the second was calling it in the viewerLoaded event part of our config file.
Neither of which seemed to result in the localstore access being disabled.

After clearing the localstore and reloading the webviewer this is what we get:

Bildschirmfoto 2019-09-05 um 22.39.43.png

Andrew Yip

unread,
Sep 6, 2019, 9:55:58 PM9/6/19
to PDFTron WebViewer
Hello,

It looked like the "viewerLoaded" event is too late to call "disableLocalStore". The local store is probably disabled (assuming your calling "disableLocalStore" correctly) so it wouldn't save to local storage when you are changing styles, but it would still print those warning on load. I added a "disableLocalStorage" option in the constructor you can use to disable it. You can use it like

WebViewer({
disableLocalStorage: true,
//  rest of your config,
}, document.getElementById('viewer'))



You can get the fix in the link below
https://pdftron.s3.amazonaws.com/custom/ID-zJWLuhTffd3c/WebViewer/WebViewer_5.2.3DisableLocalStorage.zip
You'll need to replace your "core" and "ui" folders and "webviewer.js" file

This will hopefully be merged to master sometime next week 

Andrew Yip

unread,
Sep 25, 2019, 5:47:40 PM9/25/19
to PDFTron WebViewer
Hello,

Sorry for the late response but I just wanted to inform you, we went in another direction with the fix. Instead of having to pass in "disableLocalStorage: true" in the constructor, if WebViewer detects that "localStorage" isn't accessible, it'll automatically disable it and print a warning. 

For your project, you don't need to do anything. When you eventually upgrade, WebViewer will automatically disable localStorage and there would be a warning message saying "disableLocalStorage" is not a valid constructor option (the disableLocalStorage function still exists). 

You can find the latest build with the change in the link below
https://www.pdftron.com/documentation/web/download

Please let me know if you have any questions

sbi

unread,
Sep 26, 2019, 11:06:50 AM9/26/19
to PDFTron WebViewer
Hello Andrew,

thanks for your response, the new fix should be fine for us too.
We will test the new solution when we upgrade our version and message you if something doesnt work as expected, in the meantime this conversation can be regarded as solved.

Thanks again for your help!
Reply all
Reply to author
Forward
0 new messages