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
- GH-359: Distinguish between GET and POST requests when applied beforeload. For now only GET is supported with beforeload, so document this. — committed to dpa99c/cordova-plugin-themeablebrowser by dpa99c 6 years ago
- Merge branch 'master' into GH-359-fix-beforeload-POST — committed to dpa99c/cordova-plugin-themeablebrowser by janpio 6 years ago
- GH-359: Fix beforeload to work with POST requests (#367) ### Platforms affected iOS and Android ### What does this PR do? Fixes the behaviour of `beforeload` to resolve the problem with POST r... — committed to apache/cordova-plugin-inappbrowser by dpa99c 6 years ago
On iOS with UIWebView, it should be possible to use the
NSURLRequest
object passed toshouldStartLoadWithRequest
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 theWKNavigationAction
object passed in todecidePolicyForNavigationAction
, 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 whenbeforeload
is specified. And according to this SO post, the same is true forshouldInterceptRequest()
. 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:
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.