Skip to content
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

Fix issues with WKWebView snapshots on iOS #944

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

johnpatrickmorgan
Copy link

@johnpatrickmorgan johnpatrickmorgan commented Jan 17, 2025

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's isLoading property as soon as the observation handler is called. If the observation is first called when isLoading is true, the observation is invalidated and the handler will not be called again when isLoading 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 once isLoading 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?

@johnpatrickmorgan johnpatrickmorgan marked this pull request as draft January 17, 2025 12:04
@johnpatrickmorgan johnpatrickmorgan changed the title WKWebView timeout: ensure subscription is not invalidated until isLoading becomes false Fix issues with WKWebView snapshots on iOS Jan 17, 2025
@johnpatrickmorgan johnpatrickmorgan marked this pull request as ready for review January 17, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant