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上填写付款信息后点击结账按钮时(。

我的Flutter代码:

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 View Controller或Chrome自定义选项卡中使用:https://developer.paypal.com/docs/api/info-security-guidelines/#secure-应用

不支持没有地址栏的WebView,如WKWebView或Android的平台视图

如果您的结账本身在WebView中操作,并且您需要";pop-over";对于仅用于PayPal窗口的SFVC/CCT,弹出桥库(Android或iOS版本(可能很有用。

最新更新