Fix issues with WKWebView snapshots on iOS #944
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is intended to fix a couple of issues with snapshotting
WKWebView
: #805 and #857.Timeout error (#805)
The current logic stops observing
wkWebView
'sisLoading
property as soon as the observation handler is called. If the observation is first called whenisLoading
istrue
, the observation is invalidated and the handler will not be called again whenisLoading
flips to false, meaning the view is never snapshotted, the callback is never invoked, and tests fail with timeout errors on iOS. For some reason, on macOS, invalidating the subscription does not seem to prevent the handler being called again onceisLoading
changes to false. This PR moves the invalidation so that it only happens once the web view has finished loading.Transparent images error (#857)
Once the timeout error was overcome, I found that the snapshots of
WKWebView
came back as fully transparent images on iOS. They worked well on macOS though, so I tried replicating some of the platform-specific code for macOS on iOS. I found that adding the web view to a window before snapshotting (simliar to the current behaviour on macOS) fixed the issue and the snapshots were no longer transparent on iOS.Note: When I run tests locally on iOS, I get a lot of failures for minor font size differences (the iOS snapshots seem to have been last run some years ago on iOS 13). It looks like you're not running any iOS tests on CI, so I'm not sure if you'd like me to record those as new iOS snapshots in this PR or not, or if I should try re-running on a specifc iOS device/version?