Skip to content

[WebView] Provide a way to set cookies #27597

@amourinho

Description

@amourinho

I attempted to set cookies with the evaluateJavascript function, but inspecting the webview from Google chrome shows that neither the cookie or sessionStorage item has been set.

The application has a login screen, which communicates with the server and receives a authentication token which we (in our current native applications) push to the webviews as a cookie; as our web portal applications use cookie based authentication. Some newer apps use sessionStorage, but that's another issue.

It would be nice to have this feature implemented.

Below is a the code used to display the webview in my application.

WebView(
          initialUrl: model.getUser.landingPage,
          javascriptMode: JavascriptMode.unrestricted,
          onWebViewCreated: (WebViewController wvc) {
            wvc.evaluateJavascript('document.cookie = "SESSION-${model.getUser.client}=${model.getUser.token}"; path=/');
            wvc.evaluateJavascript('sessionStorage.setItem("${model.getUser.client}_live_token", "${model.getUser.token}")');
          },
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilitycustomer: crowdAffects or could affect many people, though not necessarily a specific customer.p: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions