javascript - react 原生 : Get internal api call data from url of the WebView

标签 javascript react-native react-native-webview

我有一个带有 url 的 webview(例如支付处理页面)。加载 url 后,某些 api 调用已完成,我想知道如何从该特定 url 的内部 api 调用中获取数据。

它不像网页和 react 原生代码之间的通信。 ( window.ReactNativeWebView.postMessageonMessage )
我需要来自网页的内部 api 调用响应数据。

最佳答案

解决方案1:
您可以将 js 注入(inject) webview 以获取 api 详细信息

var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
    this.addEventListener("load", function() {
        var message = {"status" : this.status, "responseURL" : this.responseURL}
        webkit.messageHandlers.handler.postMessage(message);
    });
    open.apply(this, arguments);
};
解决方案2:
目前,没有办法拦截 webview 内部 API 调用。
您可以在 webview 中添加对此的支持
安卓
在android中你必须使用WebViewClient.shouldInterceptRequest()您可以添加桥接方法REF

关于javascript - react 原生 : Get internal api call data from url of the WebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60620388/

相关文章:

android - npm 包的多个版本导致 react-native run-android 失败

react-native - 我可以用react-native-webview渲染空HTML页面吗?

javascript - Javascript 希腊语音节库

javascript - 如何将 Rails-Jquery 添加回 Rails 应用程序?

android - 将应用程序包上传到 Google Play 控制台时出现有关 'AD_SERVICES_CONFIG' 的错误

react-native - 等待 AsyncStorage.getItem()

ios - AsyncStorage 引用崩溃 react iOS 上的 native 应用程序

javascript - 阻止 React Native WebView 访问 YouTube 网站

javascript - 事件在 Firefox 中不起作用

javascript - 如何创建 javascript 库的引用?