cordova-plugin-inappbrowser: beforeload causing POST failure

Hi i really was happy about this feature as i needed it for my app, however when i enable beforeload, it fails to send post data to the server on a forum submit. The page load goes through but does not send the post data to the server

<form accept-charset="UTF-8" action="/search_results?mobile_app=true" id="login" method="post">

activeBrowser.addEventListener('beforeload', function(e, callBack){
        console.log('before load event triggered', e, e.url);
        //prints www.someurl.com/search_results?mobile_app=true
        // so when it redirects you dont get the post data
        callBack(e.url);
      });

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 32 (18 by maintainers)

Commits related to this issue

Most upvoted comments

On iOS with UIWebView, it should be possible to use the NSURLRequest object passed to shouldStartLoadWithRequest to capture the HTTP method type and the POST data. We should then be able to use that to make a new request.

With WKWebView, while we can extract the POST data and request type from NSURLRequest *request property of the WKNavigationAction object passed in to decidePolicyForNavigationAction, according to this SO post, it’s not possible to programmatically make a POST request using WKWebView.

On Android it seems there might be an issue with intercepting POST requests in the first place. According to this SO post, shouldOverrideUrlLoading() isn’t called on POST requests and it’s that method we’re currently using to intercept the request on Android when beforeload is specified. And according to this SO post, the same is true for shouldInterceptRequest(). So there doesn’t seem to be an easy way of arbitrarily intercepting POST requests on Android.

That’s a good point - the callback basically loads the URL again, indeed POST data would not be present - I’m afraid even the method would get lost. This might also be an issue for the referer (depending on how that is derived).

To fix this, I think the following would be needed:

  • include method and POST data in the event
  • pass these on to the callback (e.g. as extra parameters)

When these arguments are missing, the GET method would be assumed. I hope this data is available in the relevant callbacks, it depends on platform support. If the method is available but POST data not, we might want to skip the callback for POST requests.