【问题标题】:Flutter Webview Apple PayFlutter Webview Apple Pay
【发布时间】:2020-12-11 06:29:33
【问题描述】:

在尝试使用 WebViewController.evaluateJavascript('myjs') 时,我在调试控制台中收到此错误。

[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'doucment.getElementById("checkout_email").value = "Hell0";'
Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=0, WKJavaScriptExceptionMessage=Unable to run user agent scripts because this document has previously accessed Apple Pay. Documents can be prevented from accessing Apple Pay by adding a WKUserScript to the WKWebView's WKUserContentController., WKJavaScriptExceptionColumnNumber=0, NSLocalizedDescription=A JavaScript exception occurred})
#0      StandardMethodCodec.decodeEnvelope 
package:flutter/…/services/message_codecs.dart:572
#1      MethodChannel._invokeMethod 
package:flutter/…/services/platform_channel.dart:161
<asynchronous suspension>
#2      MethodChannel.invokeMethod 
package:flutter/…/services/platform_channel.dart:334
#3      MethodChannelWebViewPlatform<…>

我的 Dart 文件是这样的, 在页面加载时,我做了一个简单的检查,以确保我在正确的页面上执行 js。如果检查通过,则执行 js,但不幸返回上述错误。我尝试在 Google 上到处寻找答案,但没有发现与我遇到的问题类似的东西。

  final Completer<WebViewController> _controller =
      Completer<WebViewController>();

  TextEditingController _searchQueryController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      appBar: AppBar(
        elevation: 0,
        title: _searchBar(),
        leading: _directionButton('backward'),
        actions: [_directionButton('forward')],
      ),
      body: WebView(
        initialUrl: 'https://google.com',
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (WebViewController webViewController) {
          _controller.complete(webViewController);
        },
        onPageStarted: (url) {
          _searchQueryController.text = url;
        },
        onPageFinished: (url) async {
          print('Page Finished: ' + url);
          final controller = await _controller.future;
          if (url.contains('checkouts')) {
            await controller.evaluateJavascript('doucment.getElementById("checkout_email").value = "Hello";');
          }
        },
      ),
    ));
  }

【问题讨论】:

标签: ios flutter dart uiwebview wkwebview


【解决方案1】:

尝试将此添加到您的 info.plist 中,替换您的支付网关的域

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>yourdomain.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

别忘了重新安装应用程序

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 2021-06-10
    • 2015-09-19
    • 2020-10-07
    • 2021-03-13
    • 2016-08-02
    • 2018-09-30
    相关资源
    最近更新 更多