简体   繁体   English

“未捕获的安全错误:无法从‘文档’读取‘cookie’属性:Cookies 在‘数据:’URL 中被禁用。” Flutter webview

[英]“Uncaught SecurityError: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs.” Flutter webview

WebView(initialUrl:Uri.dataFromString('<script type="text/javascript" src="https://cdn.embedly.com/widgets/platform.js"></script>'+<html>Some code</html>,mimeType: 'text/html').toString(), javascriptMode: JavascriptMode.unrestricted,),

This CDN is throwing this error:此 CDN 抛出此错误:

Uncaught SecurityError: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs." Flutter webview未捕获的安全错误:无法从“文档”读取“cookie”属性:Cookies 在“数据:”URL 中被禁用。” Flutter Z5A98E2840FD0141780D854E48CZZ608D4

You can try my plugin flutter_inappwebview , which is a Flutter plugin that allows you to add inline WebViews or open an in-app browser window and has a lot of events, methods, and options to control WebViews.你可以试试我的插件flutter_inappwebview ,这是一个 Flutter 插件,允许你添加内联 WebViews 或打开应用内浏览器 window 并且有很多事件、方法和选项来控制 WebViews。

In your case, you can use the initialData argument and set your custom HTML through the InAppWebViewInitialData.data attribute and set the InAppWebViewInitialData.baseUrl to http://localhost :在您的情况下,您可以使用initialData参数并通过InAppWebViewInitialData.data属性设置自定义 HTML 并将 InAppWebViewInitialData.baseUrl 设置为InAppWebViewInitialData.baseUrl http://localhost

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  InAppWebViewController webView;
  String customHTML = "";

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('InAppWebView Example'),
        ),
        body: Container(
            child: Column(children: <Widget>[
          Expanded(
              child: InAppWebView(
                initialData: InAppWebViewInitialData(data: """
<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>InAppWebViewInitialDataTest</title>
        <script type="text/javascript" src="https://cdn.embedly.com/widgets/platform.js"></script>
    </head>
    <body>
        $customHTML
    </body>
</html>
                    """, baseUrl: 'http://localhost'),
            initialHeaders: {},
            initialOptions: InAppWebViewGroupOptions(
              crossPlatform: InAppWebViewOptions(
                  debuggingEnabled: true,
              )
            ),
            onWebViewCreated: (InAppWebViewController controller) {
              webView = controller;
            },
            onLoadStart: (InAppWebViewController controller, String url) {

            },
            onLoadStop:(InAppWebViewController controller, String url) {

            },
          ))
        ])),
      ),
    );
  }
}

Now you have access to document.cookie using JavaScript!现在您可以使用 JavaScript 访问document.cookie

Another way is to put your HTML in an asset file (see the Load a file inside assets folder Section) and, then, you can use InAppLocalhostServer to start a local server to serve your HTML file with your script.另一种方法是将您的 HTML 放入资产文件中(请参阅在资产文件夹中加载文件部分),然后,您可以使用InAppLocalhostServer启动本地服务器来为您的 HTML 文件提供脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter Stripe Checkout:无法从“文档”中读取“cookie”属性:Cookies 在“数据:”中被禁用 - Flutter Stripe Checkout: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' Uncaught SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性 - Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement' 未捕获的SecurityError:无法从“ HTMLIFrameElement”读取“ contentDocument”属性:阻止了框架 - Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame Uncaught SecurityError:无法读取&#39;contentDocument&#39;属性 - Uncaught SecurityError: Failed to read the 'contentDocument' property SecurityError:无法从“Window”读取“localStorage”属性:拒绝访问此文档 - SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document SecurityError:无法从“ HTMLIFrameElement”读取“ contentDocument”属性 - SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement Uncaught SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止了一个源为“https:// localhost”的帧 - Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin “https://localhost” 未捕获的安全错误:无法在“文档”上设置“域”属性:“app.herokuapp.com”不是“”的后缀。 - Uncaught SecurityError: Failed to set the 'domain' property on 'Document': 'app.herokuapp.com' is not a suffix of ''. Iframe chrome:未捕获的 DOMException:无法从“窗口”读取“localStorage”属性:拒绝访问此文档 - Iframe chrome : Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document 未捕获的SecurityError:无法执行“ replacestate” - Uncaught SecurityError: Failed to execute 'replacestate'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM