【问题标题】:Using the History Web API from WKWebView & Cordova使用 WKWebView 和 Cordova 的 History Web API
【发布时间】:2018-10-08 13:11:56
【问题描述】:

我正在使用 React / Create React App / Cordova 创建一个混合应用程序。由于 UIWebView 存在一些问题,例如浮动光标和一般不符合标准的渲染,我已切换到使用 WKWebView。 WKWebView 改进了呈现问题,但我遇到了 History Web API 的问题。

作为我的核心导航/路由的一部分,我使用下面的行将代表当前页面的值推送到历史 API 中。然后我会在需要时弹出这些值并传递给自定义路由器。由于安全问题,使用 UIWebView 可以正常工作,但不能使用 WKWebView。

window.history.pushState({pageId: pageId}, null, action.pageId);

推送时出现以下错误(注意:我已用 {HASH} 替换此帖子的 ID):

SecurityError: Blocked attempt to use history.pushState() to change session history URL from file:///Users/name/Library/Developer/CoreSimulator/Devices/{HASH}/data/Containers/Bundle/Application/{HASH}/App.app/www/index.html to file:///Users/name/Library/Developer/CoreSimulator/Devices/{HASH}/data/Containers/Bundle/Application/{HASH}/App.app/www/login. Paths and fragments must match for a sandboxed document.

有什么想法吗?

【问题讨论】:

  • 我不确定这是否是一个长期的解决方案,因为我还没有完全调查,但这似乎可以防止错误:github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix
  • 你还在用这个xhrfix插件吗?我遇到了同样的问题,并且该插件对我有用(谢谢!)。值得注意的是,旧的 oracle 插件 cordova-plugin-wkwebview-file-xhr 不适用于我。

标签: javascript reactjs wkwebview hybrid


【解决方案1】:

我的项目

React JS + Cordova

问题

SecurityError: Blocked attempt to use history.pushState() to change session history URL
Paths and fragments must match for a sandboxed document.

解决方案

cordova plugin add cordova-plugin-wkwebview-engine
cordova plugin add cordova-plugin-wkwebviewxhrfix

非常简单的解决方案,但我花了几天的时间研究才把它们拼凑起来。

非常感谢插件作者!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    相关资源
    最近更新 更多