-
Notifications
You must be signed in to change notification settings - Fork 608
Custom delegate on WKWebView is replaced by mock when snapshotting #440
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
Comments
That solution sounds great to us! Thanks for raising the issue and we'd love a PR 😄 |
Also, do you know why this is necessary?
Why execute that javascript, but then no do something with the result. Do you execute it because webkit wait with executing it until the page is loaded? What about a page that never loads, for example a 404? |
This is harder than I thought because of all the optional methods. You'll need a couple of extra tests as well. PR might take some time. |
@teameh Could you do something with This is a partial example from one of my projects 😄 Obviously change the delegate/selector for the one needed by this project. It'll forward every method over automatically.
|
@Sherlouk that's a great idea! I've been fighting with this code for a while now and I think I got something that works. Regarding the line:
The docs say:
So I think you should use NSObject here:
|
See PR. It might needs to be tweaked a bit more, but it's a start. Thanks for pointing me to |
Have you got a link to that one please? We've used this code for a while and it's been working fine for us (though admittedly we're not heavy users of the delegate!) - would love to patch this upstream in our project too. Glad it was helpful and you learned something new 😄 Everyday is a learning opportunity |
😄 Sure. https://developer.apple.com/documentation/objectivec/nsobjectprotocol/1418583-responds#discussion These are the docs you get if you option-click the |
…ing wkWebView.isLoading
@stephencelis anything I can do to help move this forward? |
I ran into the same issue. |
@stephencelis anything I can do to help get this merged? |
For future ref: fixed and merged in #443 |
…tfreeco#443) * Fix pointfreeco#440 - Improve WKWebView navigation delegate * Fix pointfreeco#440 - Replace WKWebView navigation delegate by observing wkWebView.isLoading Co-authored-by: Tieme van Veen <[email protected]> Co-authored-by: Stephen Celis <[email protected]>
…tfreeco#443) * Fix pointfreeco#440 - Improve WKWebView navigation delegate * Fix pointfreeco#440 - Replace WKWebView navigation delegate by observing wkWebView.isLoading Co-authored-by: Tieme van Veen <[email protected]> Co-authored-by: Stephen Celis <[email protected]>
When a user sets a custom navigation delegate on a WKWebView and makes a snapshot of a view containing this web view, the navigation delegate may be replaced by a stub that makes sure the snapshotting lib knows when to snapshot the web view. This works great when users don't implement a custom WKNavigationDelegate themselves. But when a user implements a custom delegate themselves this fails.
Consider for example a custom delegate that limits the web view to github.com and opens the browser as soon as the user taps on a link outside of github.com
This can't be snapshot tested at the moment because the delegate is removed as soon as a snapshot is made.
I think this could be fixed by retaining the original delegate, implementing all the possible delegate methods and forwarding all the calls to the original delegate. I'll see if I can draft up a PR. Please let me know if you think of another way of dealing with this issue.
Finally, many thanks for all the work on this great lib 👏🏼 so far, hopefully I can contribute back a bit.
The text was updated successfully, but these errors were encountered: