FortuneCookie
FortuneCookie

Reputation: 1865

react-native : Get internal api call data from url of the WebView

I have a webview with a url (for example a payment processing page). When the url is loaded, certain api calls are done and i want to know how to get data from the internal api calls of that particular url.

It is not something like communication between webpage and react native code. ( window.ReactNativeWebView.postMessage or onMessage ) I need internal api call response data from the webpage.

Upvotes: 6

Views: 3194

Answers (2)

Leftium
Leftium

Reputation: 17953

I think you can inspect/log the network requests by setting up a (WiFi) proxy:

Upvotes: 0

Muhammad Numan
Muhammad Numan

Reputation: 25423

Solution 1:

you can inject js into webview to get api detail

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);
};

Solution 2:

right now, there is no way to intercept webview internal API calls.

you can add support for this in webview

Android

In android you have to use WebViewClient.shouldInterceptRequest()

you can add bridging method REF

Upvotes: 4

Related Questions