0

I need help to set multiple items in session storage of the flutter webview. I am using this package - webview_flutter: ^3.0.1 => here

I want to open a URL that will enable users to take further action in a functionality that is already present on a website. The website's code is written in a way that it accesses data from the session storage -> like auth token and user id and so on. If I am unable to provide this data in session storage then website will redirect to login.

I have tried doing this ->

          onWebViewCreated: (WebViewController webViewController) {
            _controller.complete(webViewController);
            webViewController.runJavascript(
                'sessionStorage.setItem("userCode", "000"); sessionStorage.setItem("role", "40");');
          },
Rahul Mishra
  • 368
  • 3
  • 9
  • Do you mind providing some more information about what you are trying to do and how you are trying to do it? What have you tried so far? – tomerpacific May 10 '22 at 04:56
  • I want to open a URL that will enable users to take further action in a functionality that is already present on a website. The website's code is written in a way that it accesses data from the session storage -> like auth token and user id and so on. If I am unable to provide this data in session storage then website will redirect to login. I edited the question to show what I have tried – Rahul Mishra May 10 '22 at 05:02

1 Answers1

0

I figured out a way but it does not use the official flutter webview plugin.

I used this plugin - flutter_inappwebview

I was able to set local storage and session storage both ->

                  onLoadStart:
                      (InAppWebViewController controller, Uri? url) async {
                    await controller.evaluateJavascript(source: """
                window.localStorage.setItem("userCode", "${userDetails.userId}");
              """);

                    await controller.evaluateJavascript(source: """
              sessionStorage.setItem("userCode", "${userDetails.userId}");
              sessionStorage.setItem("Role", "${userDetails.role}");
              """);
                  },
Rahul Mishra
  • 368
  • 3
  • 9