Bug 161452 - Need an API to scale the page of macOS WKWebView
Summary: Need an API to scale the page of macOS WKWebView
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: WebKit Nightly Build
Hardware: Mac OS X 10.11
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-31 12:52 PDT by Dan Saunders
Modified: 2023-08-17 23:29 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Saunders 2016-08-31 12:52:03 PDT
For one of our scenarios, we need to scale the contents of the WKWebView page to the same scale as the surrounding content outside of the control, without modifying the layout of the page. The setMagnification API on the WKWebView does allow us to zoom, but because the viewport for Mac control is always the size of the WKWebView frame at 100% zoom, scrollbars show up when zooming above 100%. We need an API similar to the behavior of -[WebView _setZoomMultiplier:(float)m isTextOnly:NO] that is available for the WebKit 1 control.
Comment 1 Dan Saunders 2017-10-06 16:59:28 PDT
We found some private API that will work. Could these be made public? There is also some accessibility benefit to allow proper zooming of WKWebView without having to add the scrollbars (⌘+ in Safari).

This private API is equivalent to ⌘+ in Safari. It seems low risk, and something that should be publicly available through an API. It is sufficient for our requirements, the only issue we found is text is the wrong size at very low zoom levels.
[_webView _setPageZoomFactor:x];

This private API does exactly what we need, but there may be other reasons why it isn't exposed since it changes the layout mode. Text and other elements have the proper scale at low zoom levels:
[_webView _setLayoutMode:_WKLayoutModeDynamicSizeComputedFromViewScale];
[_webView _setViewScale:x];
Comment 2 Teodor 2023-08-17 23:29:35 PDT
This is a significant issue now that iOS apps can be run on macOS on Apple Silicon.  It is common for macOS apps to offer in-app font size control. Some users may prefer to keep the operating system font size one size, but increase font size in text-heavy apps (e.g., messenger, news, social networking apps).

Our users are reporting problems with zoom in WKWebView-based apps. Contrary to Safari behavior, `webkitTextSizeAdjust` CSS property does not scale font size in WKWebView - all other elements of the layout are scaled, though. That limitation/issue would be fine if only this API was available and documented.

Is there a Radar for this?