【问题标题】:Webview Error Uncaught SecurityErrorWebview 错误未捕获的 SecurityError
【发布时间】:2018-07-11 09:13:18
【问题描述】:

我在 android webview 中遇到以下错误

I/chromium: [INFO:CONSOLE(1)] "Uncaught SecurityError: Blocked a frame with origin "https://xxxxxxxxxx.com" from access a frame with origin "https://xxxxxxxxx.in". 协议、域和端口必须匹配。 ",来源:https://xxxxxxxxxxxxxxx.com/v1/checkout-frame.js(1)

我的网络视图:

webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setAllowFileAccessFromFileURLs(true);
        webview.setWebViewClient(new WebViewClient());
        webview.setWebChromeClient(new WebChromeClient());
        webview.loadUrl(url);

【问题讨论】:

  • 你要加载的网址是什么
  • 这看起来像是一个Same-Origin policy 问题,应该出现在任何浏览器中。如果您认识到链接中描述的行为,您应该考虑更新标签。
  • url的证书可能有问题
  • webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
  • @sandeep 你解决了这个问题吗?苦苦挣扎。

标签: android android-webview


【解决方案1】:

我通过以下方法解决了这个问题

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }

并在清单文件应用程序选项卡中

<application
    ....
    android:usesCleartextTraffic="true"
    ...>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-05-12
  • 2014-08-18
  • 1970-01-01
  • 2017-03-26
  • 1970-01-01
  • 2017-06-14
  • 2020-05-17
相关资源
最近更新 更多