flutter - webview_flutter 违反了内容安全政策,有什么解决办法吗?
问题描述
编辑:我特别了解了 PayPal 的错误。由于某种原因,此错误仅在使用测试卡号(在沙盒模式下)时发生,尝试使用真实的信用卡号会使错误消失。我相信这是由于 PayPal 上使用 iFrame 的新货币选择功能。
我正在使用 webview_flutter 浏览 PayPal 结帐页面。它曾经可以工作,但可能是 PayPal 方面的更新破坏了它,现在我收到以下内容安全策略错误:
cancelBuffer: slot 1
I/chromium(19561): [INFO:CONSOLE(425)] "Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'nonce-PHXXXXXXXXXXXXXia13HX3l2n4' 'self' https://*.paypal.com https://*.paypalobjects.com 'unsafe-inline' 'unsafe-eval'". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
I/chromium(19561): ", source: https://www.paypal.com/webapps/xoonboarding?token=EC-1G3XXXXXX5C&country.x=CA&locale.x=en_CA&fromSignupLite=true&fallback=1&reason=dW5oYW5XXXXXZ2VuY3k%3D (425)
"Refused to connect to 'https://www.google-analytics.com/collect' because it violates the following Content Security Policy directive: "connect-src 'self' https://*.paypal.com https://*.paypalobjects.com https://*.qualtrics.com".
我尝试了不同版本的插件和不同的设备,但每次都会遇到这个错误。(当我在 PayPal 上填写付款信息后单击结帐按钮时)。
我的颤振代码:
body: WebView(
initialUrl: checkoutUrl,
javascriptMode: JavascriptMode.unrestricted,
navigationDelegate: (NavigationRequest request) {
if (request.url.contains(returnURL)) {
final uri = Uri.parse(request.url);
final payerID = uri.queryParameters['PayerID'];
if (payerID != null) {
services
.executePayment(executeUrl, payerID, accessToken)
.then((id) {
widget.onFinish(id);
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
}
Navigator.of(context).pop();
}
if (request.url.contains(cancelURL)) {
Navigator.of(context).pop();
}
return NavigationDecision.navigate;
},
),
解决方案
PayPal Checkout 只能在 Safari 视图控制器或 Chrome 自定义选项卡中使用:https ://developer.paypal.com/docs/api/info-security-guidelines/#secure-applications
不支持没有地址栏的 Webview,例如 WKWebView 或 Android 的 Platform Views
推荐阅读
- matlab - 直方图均衡代码生成索引错误
- python - Python 语句不按顺序执行?
- jquery - 在 wordpress 上更新主题版本后出现 Jquery 错误
- javascript - 如何格式化 Shiny 更新 numericInput 的输入但不更改实际值?
- html - 如何将数据从 hbs (html) 传递到 axios 发布请求?
- laravel - 如何在Vue中使用一个axios Post提交图像(formData)和字符串文本变量(数据)?
- spring-batch - 如何在spring批处理阅读器中记录导致运行时异常的数据
- jena - 使用RDFDataMgr写模型,但是用maven-assembly:assembly打包后,抛出NullPointerException
- python - 代码对黑客等级不起作用!在 Repl 和 Jupyter 上工作
- java - 将thymeleaf集成到spring boot项目中时Application Context不能为空