-
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
CB-14188: Add beforeload event, catching navigation before it happens #276
Conversation
a49c353
to
bbbe2cb
Compare
Looks nice in general. A couple major comments on my part: The idea of passing an asynchronous callback to an event listener seems really strange to me. While I can definitely understand the logic behind making it asynchronous between native and JavaScript I don't think this really justifies introducing what looks like new paradigm in event listeners. I can think of the following alternative approaches:
The code also seems to assume that there would never be multiple outstanding load requests, which I would not agree with. What if a user clicks on a couple links in succession, or the webpage JavaScript issues multiple HTTP(S) requests? [1] https://eloquentjavascript.net/15_event.html#p_nu8/BUQa7r |
Thanks a lot for your review and comments, @brodybits. I agree that the current approach is not ideal, and have struggled with how to add the callback. Indeed, a synchronous callback would be the best option, that would first need some research to whether Android's and iOS's WebView implementation allow this to take a little time (because it involves a Javascript invocation). If this is not possible (or if this is ported to a platform requiring near-immediate return from its do-I-need-to-load-this-URL-function), for Cordova users it can still be a synchronous function, with the help of a workaround similar to what happens now, but without the concurrency issue you mentioned (I have an idea to do this using a custom URL scheme). Interesting you mention the I'll delve into this. Since I'll be on holiday for about two weeks, it may take a little time. |
Reading up on HTML's I would suggest to adopt |
I'd also suggest to explicitely enable the event (with an option like |
Hey, I just fixed the problem that caused Android tests to fail in |
bbbe2cb
to
228703a
Compare
@janpio still failing on Android 7 :( |
Yep, you are unfortunately hitting this: #307 |
And passing :) (context: #307 (comment)) |
Looks OK to me, merging |
This is already merged now, but can this be added to the tests and checked automatically that it works? |
Oh, wait, wasn't expecting this to be merged already ... I was still coming back to processing the feedback of @brodybits on the callback mechanism. I suppose these points are still valid ... ? I'm also ok with having this PR included right now (so the feature can be used), and changing the API later (in a next major release), if somebody has a better way of implementing it. Or mark the API as unstable, so it can be changed in a point release. What shall we do? |
this.webView = webView; | ||
this.edittext = mEditText; | ||
this.useBeforeload = useBeforeload; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2 vars that will always store the same value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this is merged already, but perhaps my reply will serve as a reference)
waitForBeforeload
is the current state, whether we need to wait a call back from JS to really load next time it is encountered. useBeforeload
indicates whether the beforeload
event is used at all (see the end of shouldOverrideUrlLoading
).
Yes, I agree that the feedback is valid - I have no idea why @brodybits just merged it after giving this feedback himself. Could you please create a new PR and refer to this one so it all gets connected? Thanks. |
I was hoping to unblock forward progress, looks like it wasn't so good. I cannot promise when I will get a chance to follow up again. Sorry for the troubles. @wvengen I do stand by the feedback I gave before, would like to treat them as minor points in case anyone has a chance to do it better someday. |
Not a blocker, just a little nit. |
Ah, that clears it up. And thanks for merging: with these minor points I think it indeed makes sense to include it already, and if interest in this feature would increase, it can be improved. Thanks again for your support, @brodybits! |
For both UIWebView and WKWebView implementations on iOS. <!-- Please make sure the checklist boxes are all checked before submitting the PR. The checklist is intended as a quick reference, for complete details please see our Contributor Guidelines: http://cordova.apache.org/contribute/contribute_guidelines.html Thanks! --> ### Platforms affected iOS ### What does this PR do? Fixes `beforeload` event (introduced by #276) for iOS ### What testing has been done on this change? Tested both allow & deny loading of URL with both iOS implementations in [test container app](https://github.com/dpa99c/cordova-plugin-inappbrowser-wkwebview-test) (ignore its README). - To test with UIWebView use options: `beforeload=yes,usewkwebview=no` - To test with WKWebView use options: `beforeload=yes,usewkwebview=yes` ### Checklist - [x] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database - [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected. - [x] Added automated test coverage as appropriate for this change. closes #349
Sorry for the simple question, is this in the current release (v3.0.0)? |
This gets rid of the previous workarounds by using the beforeload event introduced in apache/cordova-plugin-inappbrowser#276
This gets rid of the previous workarounds by using the beforeload event introduced in apache/cordova-plugin-inappbrowser#276
Platforms affected
Android, iOS
What does this PR do?
Implements CB-14188: support for a callback that determines whether a URL to be loaded in the inAppBrowser should be loaded or not.
What testing has been done on this change?
On iOS & Android emulators (will test on real devices soon).
Checklist
Example