Flutter InAppWebView 无法在发布模式下访问 localstorage 获取“无法从 'Window' 读取 'localStorage' 属性”错误消息

问题描述

我正在尝试将 webview Flutter 应用程序迁移到纯 Flutter 应用程序。 以前,该应用程序使用 inapp webview plugin 并向用户加载网络应用程序。现在我已经将整个 web 应用程序转换为 Flutter.And,我不想让现有用户再次登录新应用程序。为此,我尝试在无头 webview 中加载 webapp(使用相同的插件 - inapp webview)并获取存储在 localstorage 中的令牌。

问题是在调试模式下一切正常,但在发布模式上我收到此错误 Failed to read the 'localStorage' property from 'Window'。我知道这是一项安全功能 - 并且 webview 插件具有启用/禁用此功能的标志。正如我所说,我让它在调试模式下工作,但在发布模式下不起作用。 有人可以帮我吗?

headlessWebView = HeadlessInAppWebView(
  initialUrl: "https://www.google.com/",initialOptions: InAppWebViewGroupOptions(
    android: AndroidInAppWebViewOptions(
        allowContentAccess: true,builtInZoomControls: true,thirdPartyCookiesEnabled: true,allowFileAccess: true,geolocationEnabled: true,supportMultipleWindows: true),crossplatform:
        InAppWebViewOptions(debuggingEnabled: true,cacheEnabled: true),),onWebViewCreated: (controller) async {
    // controller.webStorage.localStorage.
    Map<String,dynamic> _data = Map<String,dynamic>.from(
        await controller.webStorage.localStorage.getItem(key: 'data'));
  },);

这是我的代码,我在调试模式下获得了 _data 的价值,但在发布模式下没有获得价值。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)