无法在Flutter WebView中将HTML与脚本一起使用

时间:2020-05-25 17:27:50

标签: javascript flutter webview flutter-web flutterwebviewplugin

我从一个站点获得了html代码,并试图在Flutter Webview中使用它,但没有任何反应。当我从chrome中正常打开文件时,一切看起来都不错。 这是我的html代码:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script src="https://export.otpusk.com/api/session?access_token=***"></script>
<script src="https://export.otpusk.com/js/onsite/"></script>
<script src="https://export.otpusk.com/js/order"></script>
</body>
</html>

我如何使用它:

  String filePath = "assets/index.html";
  WebViewController webViewController;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("App bar"),),
      body: WebView(
        initialUrl: 'about:blank',
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (WebViewController webview){
          webViewController = webview;
          _loadHtmlFromAssets();
        },
      ),
    );
  }
  _loadHtmlFromAssets() async{
    String fileHtmlContents = await rootBundle.loadString(filePath);
    webViewController.loadUrl(Uri.dataFromString(fileHtmlContents,mimeType: 'text/html',encoding: Encoding.getByName('utf-8')).toString());
  }

在控制台中,我得到如下信息:

I/chromium(13344): [INFO:CONSOLE(1)] "A parser-blocking, cross site (i.e. different eTLD+1) script, https://export.otpusk.com/jsapi/onsite.min.js?_time=20200525, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details.", source: https://export.otpusk.com/js/onsite/ (1)
I/chromium(13344): [INFO:CONSOLE(1)] "A parser-blocking, cross site (i.e. different eTLD+1) script, https://export.otpusk.com/jsapi/onsite.min.js?_time=20200525, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details.", source: https://export.otpusk.com/js/onsite/ (1)
I/chromium(13344): [INFO:CONSOLE(24)] "Uncaught SecurityError: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs.", source: https://export.otpusk.com/jsapi/onsite.min.js?_time=20200525 (24)

请帮助我,如何解决此问题或如何仅加载网站的一部分而不是全部?

0 个答案:

没有答案