Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to enable localStorage in WebView panels #52246

Closed
jdgarcia opened this issue Jun 19, 2018 · 10 comments
Closed

Option to enable localStorage in WebView panels #52246

jdgarcia opened this issue Jun 19, 2018 · 10 comments
Assignees
Labels
feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code webview Webview issues

Comments

@jdgarcia
Copy link

I am currently using the vscode.previewHtml command to display a web app in VS Code (via iframe) which uses localStorage to store persisting state, and I am currently trying to convert it to use the new Webview API, in order to take advantage of the new retainContextWhenHidden option. I noticed however that while accessing localStorage works fine when using vscode.previewHtml, it is disabled in panels that use the Webview API.

I saw that a persistence API is currently being worked on (#49022), but in order to even use that, I would have to wrap all my localStorage gets/sets in async functions that check to see if localStorage is accessible, and if it isn't, use message passing between the iframe and the webview in order to use getState/setState inside the webview.

That would be doable but it's definitely not ideal.

This comment seems to imply that it is disabled intentionally but is something that can potentially be enabled.

@vscodebot
Copy link

vscodebot bot commented Jun 19, 2018

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@jrieken jrieken assigned mjbvz and unassigned jrieken Jun 19, 2018
@mjbvz mjbvz added webview Webview issues feature-request Request for new features or functionality labels Jun 19, 2018
@mjbvz
Copy link
Collaborator

mjbvz commented Jun 19, 2018

It's disabled because we serve webview using data uris: https://stackoverflow.com/questions/37379254/how-to-save-data-to-the-browser-with-data-url/37541068

@formulahendry
Copy link
Member

Do we have plan to enable this? I meet with the same issue on https://marketplace.visualstudio.com/items?itemName=formulahendry.vscode-node-red extension. Currently, we are using vscode.previewHtml but want to use retainContextWhenHidden in new WebView API. However, localStorage is not enabled..

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 17, 2018

@formulahendry You should not need local storage. See the new persistence APIs instead

@formulahendry
Copy link
Member

Hi @mjbvz , in my extension, I embed https://www.npmjs.com/package/node-red (which is just a localhost website) into the webview. I have no control of node-red npm package to not to use local storage.. Any suggestion would be appreciated. Thanks!

@jrieken
Copy link
Member

jrieken commented Jul 18, 2018

It a WebView, not a WebBrowser ;-) I don't think we can isolate local storage of web views with the local storage VS Code is using That would be cross pollution that's generally undesirable for us.

@formulahendry
Copy link
Member

If we have no plan to support that in WebView, do we have plan to make vscode.previewHtml not re-render when switching? I really need the page to be retained. 😢

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 18, 2018

No. You should use a webview. The old html preview is deprecated and will not receive new features

@formulahendry
Copy link
Member

OK, so seems like I need to wait for localStorage to be enabled in WebView.

@mjbvz mjbvz added the *out-of-scope Posted issue is not in scope of VS Code label Aug 24, 2018
@vscodebot
Copy link

vscodebot bot commented Aug 24, 2018

This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code webview Webview issues
Projects
None yet
Development

No branches or pull requests

4 participants