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

Viewed 1049

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.

2 Answers

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

Related