Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercepting AJAX request is not working in Android. #176

Closed
vijayawoshe opened this issue Oct 17, 2019 · 2 comments
Closed

Intercepting AJAX request is not working in Android. #176

vijayawoshe opened this issue Oct 17, 2019 · 2 comments

Comments

@vijayawoshe
Copy link

vijayawoshe commented Oct 17, 2019

I am trying to intercept the ajax requests in webview. In IOS it is working fine always. but the same injecting script code is not working on android. Strange thing is it is not throwing any particular error.

Could you please help me, I need this ASAP.
I am using the following Javascript code for intercepting:

var open = window.XMLHttpRequest.prototype.open,
    send = window.XMLHttpRequest.prototype.send,
    onReadyStateChange;

function openReplacement(method, url, async, user, password) {
console.log('new data22');
    var syncMode = async !== false ? 'async' : 'sync';
    if (url === '/api/fakeCall') {
        console.log('Preparing ' + syncMode + ' HTTP request : ' + method + ' ' + url);
    }
    return open.apply(this, arguments);
}

function sendReplacement(data) {
    console.log('Sending HTTP request data : ', data);

    if(this.onreadystatechange) {
        this._onreadystatechange = this.onreadystatechange;
    }
    this.onreadystatechange = onReadyStateChangeReplacement;
    return send.apply(this, arguments);
}

function onReadyStateChangeReplacement() {
    console.log('HTTP request ready state changed : ' + this.readyState + ' ' + this.readyState + ' ' + XMLHttpRequest.DONE);
    if (this.readyState === XMLHttpRequest.DONE) {
        if (this.responseText !== "" && this.responseText !== null) {
            if (this.responseText.indexOf('fareSessionUUID') !== -1) {
                console.log('________________response____________');
                var oData = JSON.stringify({'data': this.responseText});
                    console.log('new data');
                    console.log(oData);
                window.flutter_inappbrowser.callHandler('myHandler', {foo: oData}).then(function(result) {
                    console.log(result, typeof result);
                    console.log(JSON.stringify(result));
                })
            }
        }
     }
    if (this._onreadystatechange) {
        return this._onreadystatechange.apply(this, arguments);
    }
}
console.log(openReplacement.toString());
window.XMLHttpRequest.prototype.open = openReplacement;
window.XMLHttpRequest.prototype.send = sendReplacement;
@pichillilorenzo
Copy link
Owner

Hi @vijayawoshe, try to set the Android WebView option domStorageEnabled to true.

This was referenced Jul 6, 2020
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants