I want to set some key&value pairs in local storage of my WebView in my flutter app. I am using the library called flutter_webview_plugin.
I am aware of this question.
Eventually i want to set a token, in order to reach a authentication-required URL directly, which is stored as 'jwt_token' in Chrome's local storage.
The library i use provides a withLocalStorage
property, and a evalJavascript
method:
flutterWebviewPlugin
.launch("SOME_URL",
withLocalStorage: true, withJavascript: true,)
.whenComplete(() {
flutterWebviewPlugin.evalJavascript("window.localStorage.setItem('key', 'key')");
flutterWebviewPlugin.evalJavascript("alert(window.localStorage.getItem('key'))");
flutterWebviewPlugin.evalJavascript("alert('test alert')");
After running the code above the "test alert" pops in my webview browser, which indicates that evalJavascript
method is working correctly, but the prior alert with the localStorage.getItem
method does not pop. I have tried with and without window object, all '' "" combinations and the result is the same. I cannot set information in my local storage with this JS method. Can you help me please ?