MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
450 stars 55 forks source link

localStorage JavaScript API missing #2289

Open dongle-the-gadget opened 2 years ago

dongle-the-gadget commented 2 years ago

Description

The localStorage JavaScript API seems to be completely missing. Using either DevTools console or CoreWebView2.ExecuteScriptAsync always results in the error saying localStorage is undefined.

Version

SDK: 1.0.1150.38 Runtime: Stable 99.0.1150.39 Framework: WPF OS: Windows 11 Insider Build 22572

Repro Steps

  1. Open DevTools, go to Console tab, and try to execute localStorage. Expected result: DevTools shows the JSON implementation of localStorage. Actual result: DevTools throws Uncaught ReferenceError: localStorage is not defined.
  2. Execute CoreWebView2.ExecuteScriptAsync("javaScript:localStorage"); Expected result: The function returns the JSON implementation of localStorage. Actual result: The function returns null.

Screenshots

image image image
champnic commented 2 years ago

Hey @dongle-the-gadget - I just gave this a try and localStorage is showing up fine for me on a 99.0.1150.46. Are you navigating to that page in a special way? Can you share a sample app that demonstrates this issue? Thanks!

LingleDev commented 2 years ago

Discord intentionally destroys the localStorage object so automated scripts cannot set the token localStorage object, which would grant them access to user accounts.

champnic commented 2 years ago

Thanks for the info @LingleDev. So I guess the ask here is to expose the localStorage API when the page purposefully hides the API? It's possible you can do this today using Chromium Devtools Protocol: https://chromedevtools.github.io/devtools-protocol/tot/Storage/

And call it on the WebView2: https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.calldevtoolsprotocolmethodasync?view=webview2-dotnet-1.0.1264.42#microsoft-web-webview2-core-corewebview2-calldevtoolsprotocolmethodasync(system-string-system-string)