-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
beforeload causing POST failure #359
Comments
What platform? What OS version? I am not sure I am following.
|
iphone xs ios 12, i am trying to implement cacheing with the beforeload event, however if i include the beforeload even on a simple passthrough like the example i posted, post data within a form gets lost, the server gets the hit but without any post data. Everything works ok when i dont have the event listener or beforeload=no.
|
Could you create a super simple reproduction app that helps reproduce this issue? Start a new Cordova app with |
I dont have a server i can give you access to to make the server hit, i made a slightly more complete html/js structure maybe this helps. On button click submit, the form hits the server at "/search_results?mobile_app=true", but the input value is lost, possibly the url data you are useing does not include post data, thus the server only gets the url without the attached data, i looked through the code:
|
POST or GET?
Probably will, but having a ready made app one just has to check out and build/run would be even better - saves a few minutes of work for the maintainer. |
post, its in the form attribute, method="post" in the example |
That I see. But is the request that is missing the POST data really a POST? |
yes it is a POST |
Ok thanks, now a future maintainer looking into this knows what to look at and for. |
@dpa99c you added this feature correct? Any insights or ideas on what it could be, maybe it needs an alternate to using navigationAction.request.URL; as that seems to be only communicating the url without getting the data sent with it? |
Not sure, however i dont think my app will work properly in UIwebview, it was built in wkwebview in a fork of the inappbrowser, but i switched back to master after the release of wkwebview. ill give it a shot though and give some feed back soon, thanks. |
@dpa99c , I tested with "usewkwebview=no" same issue. |
@keenan35i OK, that implies the issue must've been present in the original UIWebView implementation in #276 and that I've translated the same problem across to the WKWebView implementation in #350. @wvengen any ideas how this could be resolved in your original UIWebView implementation (i.e. preservation of POST data in the intercepted request)? |
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 |
On iOS with UIWebView, it should be possible to use the With WKWebView, while we can extract the POST data and request type from On Android it seems there might be an issue with intercepting POST requests in the first place. |
In regards to IOS (wkwebview), why not just pass the POST data back to a js function within the plugin js that can handle creating a secondary POST function after the logic determines which url to hit if any. |
@keenan35i that would be a possible workaround for WKWebView POST requests, but it's a bit hacky. In the case of both GET and POST, we'd ideally want to preserve any request headers also, particularly given that custom request headers is something that's being considered as a feature in #361. |
Ok in that case, can we disable listening to POST requests and rename it to beforeGETLoad, adding beforePOSTLoad in the future as a different feature, at least i would be able to use this feature instead of it causing the app to break. |
What about: |
Better solution, if really necessary, would probably be to only handle |
|
This should work for both iOS implementations. On Android, we have no way of intercepting the initial POST request anyway so it will proceed (along with its POST data) regardless of whether |
@wvengen I'm working on a PR to address this issue. iOS is done, but on Android I'm finding that on testing the existing implementation on the I'm debugging it in Android Studio and while the breakpoint on Any idea why this might be? I'm testing on a device running Android 8.1 and using this test project using Note that if I insert an override for |
…beforeload. For now only GET is supported with beforeload, so document this.
OK, I've figured it out: on Android On iOS (both implementations), the relevant callbacks are always invoked for both initial and subsequent navigation. |
I've created a PR to address the cause of this issue and to leave the future possibility open of supporting interception of POST requests using Please give my branch a test:
I've also created a test app container which I used to validate this:
|
The link you provided is for themeable browser plugin not in app browser plugin? |
Don't be misled by the name: the repo is called However the branch Fun with git: you can have multiple remotes! |
ah ok thanks, will test it out and let you know if it works for my app. |
Just tested it seems to be working great, |
@dpa99c do you happen to have a branch with both this fix and the postMessage API feature together? Seems to be taking a while for the PR's to be merged and im trying to finish building my cacheing tool which uses both of these features. |
@keenan35i I've kept the changes associated with both PRs separate so as not to confuse the PR review process. You can always checkout both of my PR branches and merge them into your own combined fork for now. But yeah, it would be good to get this merged to master, as well as #362 |
### Platforms affected iOS and Android ### What does this PR do? Fixes the behaviour of `beforeload` to resolve the problem with POST requests outlined in #359. The `beforeload` parameter has been changed from taking only a boolean (`yes` or not defined) to a discrete string with possible values of `get`, `post`, or `yes` which correspond to request types of GET, POST or GET&POST respectively. The `README.md` has been updated to reflect this. Note that use of `beforeload` to intercept POST requests is currently not supported on Android or iOS, so if `beforeload=yes` is specified and a POST request is detected as the HTTP request method, `beforeload` behaviour will not be applied. If `beforeload=post` is specified, a `loaderror` event will be dispatched which states that POST requests are not yet supported. #### Notes for Android The `shouldOverrideUrlLoading()` override method has been updated to support the [new method interface added in API 24 / Android 7][1] which receives the `WebResourceRequest` instead of just the `String url`, enabling the HTTP method of the request to be determined. The [deprecated method interface][2] has also been preserved for API <=23, but in this case the HTTP method cannot be determined so is passed as null. Also note that due to a [Chromium bug](https://bugs.chromium.org/p/chromium/issues/detail?id=155250), `shouldOverrideUrlLoading()` is currently not called for POST requests. It's possible this may be resolved in a future Chromium version in the Android System Webview (given that this is now self-updating and independent of Android version since Android 5.0) - in prospective anticipation of this, code to handle POST requests has been added to `shouldOverrideUrlLoading()`. However, it seems more likely that this won't be resolved any time soon given that [a Chromium dev said](https://bugs.chromium.org/p/chromium/issues/detail?id=155250#c39): > We're looking at implementing a better way to handle request interception in a future OS version. There's no way to just "fix" this, the API doesn't accommodate this usage at all. This will not be something you can use any time soon. Therefore if we want to go ahead and use `beforeload` to intercept request types other than GET, it's likely we'll instead need to use the `shouldInterceptRequest()` method override. As with `shouldOverrideUrlLoading()`, there are a two variants: the [new method interface][3] added in API 21 / Android 5.0 which which receives the `WebResourceRequest` object and the [deprecated one][4] which receives only `String url`. If we want to determine the HTTP request method, we'll need to use the new implementation. This has been empirically tested and *is* called for POST requests so would allow the possibility to intercept, delay, modify and send the POST request and its data via `beforeload`. Both `shouldInterceptRequest()` method interfaces have been exposed in the Android implentation for potential future use but they currently do nothing other than return the unadulterated request object. ### What testing has been done on this change? Manual testing of POST and GET requests on both platforms using a test app container: https://github.com/dpa99c/cordova-plugin-inappbrowser-test [1]: https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView,%20android.webkit.WebResourceRequest) [2]: https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String) [3]: https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest) [4]: https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldInterceptRequest(android.webkit.WebView,%20java.lang.String)
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">
The text was updated successfully, but these errors were encountered: