wkwebview中的条带打开浏览器页面加载脚本

问题描述

由于苹果的需求,我们正在将我们的APP移至新的新wkweview。

其中一个应用程序正在使用StripeJS sdk,以便允许在应用程序中付款。当APP正在引导时,并且条带sdk包含以下代码时,会发生问题:

// Payment service is not initialized yet
      $.ajax({
        type: "GET",cache: true,url: "https://js.stripe.com/v3/",dataType: "script",error: function(XMLHttpRequest,textStatus,errorThrown) {
          Logger.error("An error ocurred during SDK download");
          def.reject();
        },success: function() {
          Logger.debug("Stipe JDK downloaded correctly");
          initialized = true;
          def.resolve();
        }
      });

我们已经尝试在index.html中使用''head标签或动态创建一个脚本TAG并将其附加到正文:但是没有人解决此问题。

脚本包含测试

[Angular $ http method]

$http({
   method: "GET",url: "https://js.stripe.com/v3/"
}).then(
   function(res) {
      angular.element("body").append("<script>" + res.data + "</script>");
   },function(err) {
      def.reject();
   });

[index.html]

<html>
  <head>
     <script type="text/javascript" src="https://js.stripe.com/v3/"></script>
  ...

问题

打开浏览器页面,APP留在后台;更具体地说,“ METRICS_CONTROLLER”的情况是在第767行的切换中捕获的(请参见url https://js.stripe.com/v3/>的库)。

有人知道为什么要打开浏览器页面包括该脚本吗?

解决方法

为回答我的问题,我们发现了问题。

问题与cordova配置(文件'config.xml')不允许的浏览URL权限有关。 更具体地说,我们需要在配置中添加以下行。文件

<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />

最后,我们的CORS权限定义为:

<access origin="*" />
<allow-intent href="sms:*" />
<allow-intent href="tel:*" />
<allow-intent href="geo:*" />
<allow-intent href="mailto:*" />
<allow-intent href="file://*/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />

'*'是因为APP可以触发外部资源,所以我们无法知道用户将在APP中打开哪个url。

希望这项帮助@saperlipopette 西蒙

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...