0

我从一个站点获得了 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)

请帮助我,我该如何解决这个问题,或者我如何只加载网站的一部分,而不是全部?

4

0 回答 0