Repository navigation
feat: WebView on Windows and Linux, built on webview_all for every platform - #7124
Draft
ndonkoHenri wants to merge 13 commits into
Draft
ndonkoHenri wants to merge 13 commits into
ndonkoHenri wants to merge 13 commits into
Conversation
`flet-webview` now uses the `webview_all` Flutter package family on Android, iOS, macOS, Windows, Linux and web, instead of `webview_flutter` and `webview_flutter_web`. Windows (Edge WebView2) and Linux (WebKitGTK) get a working WebView, and on web the methods and events work for same-origin pages and HTML loaded with `load_html()` instead of only showing the initial `url`. The four platform-split Dart implementations collapse into one, on the app-facing `webview_all` WebViewController. The platform extras (Android file access, Linux file-URL creation params, Windows/Linux controller disposal) sit behind a `dart.library.io` conditional import, which unlike the previous `dart.library.html` key also holds under dart2wasm. All eight `webview_all` packages are pinned exactly, to 1.4.4: they depend on each other with caret constraints, so pinning the umbrella alone would let the rest float. 1.4.0 is the oldest release that can share an app with the `webview_flutter` that `google_mobile_ads` (flet-ads) pulls in; earlier ones registered the same platform view type and channel names. Both stacks are linked side by side in the client on Android, iOS and macOS. Behaviour details: - Initialization is serialized (delegate, subscribed handlers, JavaScript mode, initial load), because Windows and WKWebView install the console and scroll bridges as scripts that only reach later documents. Invoked methods wait for it, and a failed initial load (e.g. a `url` without a scheme) is logged rather than failing every later method call. - `onNavigationRequest` is only registered while `prevent_links` is not empty: on Windows an intercepted navigation is cancelled and started again as a GET, which drops a submitted form's body. - The alert handler stays lazy, since setting it suppresses the built-in dialog on Android, WebKitGTK and web. - WKWebView's zoom state is synced at init on macOS, where the controller assumes zoom is on while magnification starts off. - `bgcolor` is applied once per change and never throws inside `build()`; the previous macOS implementation threw synchronously there. Python: every method used to be rejected on web, Windows and Linux. Now only what cannot work is rejected: `load_file`, `clear_cache` and `clear_local_storage` on web (the last two would clear the Flet app's own storage there) and `scroll_to`/`scroll_by` on macOS. The docstrings describe the per-platform limits. Linux: `webview_all_linux` links webkit2gtk-4.1 into the whole binary, and that library is absent before Debian 12 / Ubuntu 22.04. `flet_webview` is therefore gated in the client behind `--WEBVIEW_*--` markers and a `webview_enabled` CI matrix flag, and kept out of the light flavor. The build-test workflows install `libwebkit2gtk-4.1-dev`. It is not added to flet-cli's `linux_dependencies`, which is published as a copy-paste apt one-liner and has to stay installable on older distributions. Checked with an automated harness covering the 19 methods, 8 events, `prevent_links`, `bgcolor`, `url=file://`, re-creation and a bad initial `url`: macOS client 34/34, iOS simulator `flet build` with flet-ads 34/34, and web (wasm) client 31/33, where both misses are the documented limit on links followed to another origin. Android, Windows and Linux were not run.
…se builds On iOS and macOS, webview_all keeps the setOnConsoleMessage handler only in JavaScriptChannelParams.onMessageReceived, and the native script message handler reaches it through a weak reference. No code reads that field, so the AOT compiler drops it as write-only in release builds, the handler is garbage collected and console messages stop after the next collection. Reading the field once when the handler is registered keeps it (verified in a macOS release build: 29/30 before, 30/30 after). Also document that on Android scroll positions and amounts are physical pixels and that console.info() arrives with the LOG severity level.
webview_all_windows 1.4.4 serves loadFile() from a WebView2 virtual host mapped to the file's folder, and Set/ClearVirtualHostNameMapping return the WebView2 HRESULT from a bool function, so every successful removal of the mapping is reported as a failure. After any loadFile(), every loadRequest(), loadHtmlString() and loadFile() of another folder threw PlatformException(method_failed) until the WebView was disposed. On Windows, load_file and url=file:// now navigate to the file's file:/// URL instead, which needs no mapping; WebView2 resolves the page's sibling files relative to it. The page gets a file: origin, so fetch, XHR and JavaScript modules can't read local files from it (they could under the virtual host); the docstring says so. Verified on Windows 11 with WebView2 154: the load-file probes went from 14 failures to none, and get_current_url now reports the file:/// URL.
…e Linux requirement - load_request(): on Windows a POST request fails, because webview_all_windows 1.4.4 sends it without a body. - on_progress: in web apps compiled to JavaScript, while on_scroll is set, a cross-origin page reports only 0 (dart2js strips webview_all_web's cross-origin probe, so the scroll listener throws before progress 100). - CHANGELOG: list the full Linux client's new libwebkit2gtk-4.1-0 requirement under breaking changes, and add the Linux run/build requirements to the flet-webview changelog.
Pins all eight webview_all packages (the umbrella, the six platform implementations and webview_platform_interface) to exactly 1.5.2, and updates client/pubspec.lock to match. They depend on each other with caret constraints, so every package stays pinned to keep the set on one release. Upstream fixes picked up since 1.4.4 include scroll callbacks that stopped after a page rewrote its document (Linux, Windows, web), Windows loadHtmlString reporting success when the load failed, and Windows session cookies disappearing before the first page load. 1.5.0 requires iOS 14 and macOS 11; the client targets iOS 15 and macOS 12. No Dart changes were needed: `flutter analyze` on flet_webview reports no issues, and the macOS debug client builds.
Removes the private `_check_platform_support()` helper. The methods that are not supported everywhere now raise `FletUnsupportedPlatformException` in their own body, as other extensions such as flet-geolocator do: - `load_file()`, `clear_cache()` and `clear_local_storage()` on web; - `scroll_to()` and `scroll_by()` on macOS desktop. A web app opened in a browser on a Mac reports the macOS platform too, so the check excludes web, where scrolling works. The other methods no longer check anything before calling `_invoke_method()`, which already raises when the control has not been added to a page. Behavior is unchanged.
The class docstring's Note held the Windows, Linux and web requirements and limits as three paragraphs. They are now one bullet per point: the Windows runtime, the Linux library, the Linux native-widget limits, the web iframe embedding limits, and the web cross-origin limits.
…ted packages Adds website/docs/reference/linux-system-libraries.md (Reference sidebar) as the single place for the system packages Linux apps need: - what to install for each case: light client, full client, `flet build linux`, shipping a built app; - a table by extension (every app, flet-secure-storage, flet-audio, flet-video, flet-webview, flet-rive) with the desktop client flavor, the runtime and build packages, and the oldest distribution; - the full desktop client's install command per distribution: Debian 12+ / Ubuntu 24.04+, Ubuntu 22.04, Debian 11 / Ubuntu 20.04, Fedora, openSUSE Tumbleweed, Rocky/AlmaLinux 9 (EPEL + CRB); - what a missing library looks like: exit 127 and the loader error, before any app code runs. The installation, Video, Audio, WebView, flet pack and publish/linux pages now link to it instead of repeating package lists. publish/linux's two "won't start" troubleshooting rows become one, its .deb and .rpm recipes point to the runtime packages per extension, and FLET_LINUX_DISTRO's table lists libwebkit2gtk-4.1.so.0 for the builds that load it. The flet pack page lists WebView among the extensions the light client leaves out. flet-desktop's startup hint for a client that exits with 127 now names WebKitGTK and `libwebkit2gtk-4.1-0` for the full client, and links to the new page. CHANGELOG 1.2.0 gains two breaking changes (flet build linux apps including flet-webview need WebKitGTK; WebView.scroll_to/scroll_by raise on macOS) and a Documentation entry. The package names and the missing-library behavior were checked in Debian 11/12, Ubuntu 20.04/22.04/24.04, Fedora 44, openSUSE Tumbleweed and Rocky 9, with full and light clients built as CI builds them. The docs build passes.
…5.2 retest The harness and per-claim probes were re-run on webview_all 1.5.2 on macOS (client and release build), iOS simulator, Android, web (JS and wasm), Ubuntu 24.04 (Wayland and XWayland) and Windows 11. The notes that no longer match are updated: - Linux clips: rectangular clips and a Card's rounded corners apply to the WebView; other clips, such as a Container with border_radius or a circular shape, still hide it. - Linux load_request POST: it now carries the WebView's cookies and keeps the ones its response sets; a failed request still raises instead of firing on_web_resource_error. - on_scroll: a handler set after mount fires on the current page on Windows, and on web it fires for same-origin pages and HTML loaded with load_html, not only the first page. - With the canvaskit web renderer (the default for static web apps, and what `auto` picks outside Chromium), setting on_scroll keeps on_page_ended from firing for cross-origin pages and POST responses (reported upstream as abandoft/webview_all#55). on_scroll, on_page_ended and on_progress say so. - on_url_change, get_current_url and reload on web: after a link to another origin they use the last URL the WebView could read.
Adds the PR link to the 1.2.0 entries for the webview_all migration, in CHANGELOG.md and in the flet-webview package changelog, next to the issue links.
Deploying flet-website-v2 with
|
| Latest commit: |
7579244
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cd591469.flet-website-v2.pages.dev |
| Branch Preview URL: | https://feat-webview-all-1-1.flet-website-v2.pages.dev |
…url updates From a Codex review of PR #7124, each finding checked against the code and the webview_all 1.5.2 sources: - A WebView put in the place of another one gets its own state and native webview: the extension keys it by control id (or the user's key). Before, Flutter reused the old state, so the replacement never loaded and its method calls timed out. - Property updates (prevent_links, event subscriptions, url) run in order through one path, and every method call waits for the latest one, so a load_request right after update() sees the new prevent_links. - prevent_links is also checked for loads the app starts (load_request, url): Android's loadUrl skips the navigation delegate. - Changing `url` loads the new URL. - A `url` that can't be loaded, and a certificate error, fire on_web_resource_error; a certificate error also cancels the load. - Setting on_scroll to None unsubscribes (setOnScrollPositionChange(null)), which also ends the canvaskit page_ended loss of abandoft/webview_all#55 for that WebView. - On web, removing a WebView closes its iframe session (closeWebViewSession) instead of leaving it to garbage collection. - A method call that resumes after the WebView was removed raises instead of using a disposed controller. - The initial load no longer reads a `method` property, which Python never sends. Docstrings of `url` and `on_web_resource_error` describe the new behavior; both changelogs list it, and the main feature entry is shorter. Tested with a probe for these fixes (review_fixes.py) and the full harness on the macOS client, iOS simulator, Android emulator, Ubuntu 24.04 Wayland, Windows 11 and web (canvaskit and skwasm): every probe check passes, and the harness matches its pre-fix baseline on each platform.
The Rocky Linux and AlmaLinux 9 tab of the Linux system libraries page said to build the client locally against the installed libraries, which fails for a WebView app: these releases ship only WebKitGTK 4.0. The local build advice is now for audio and video, and a separate sentence says WebView isn't available there.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
flet-webviewnow useswebview_allon every platform, instead ofwebview_flutterandwebview_flutter_web.WebViewgains Windows (Edge WebView2) and Linux (WebKitGTK) support, and its methods and events now work on web for same-origin pages and HTML loaded withload_html().Closes #6530, closes #5934. Supersedes #6836.
What changed
Dart (
flet_webview)lib/src/webview.dartreplaces the three per-platform implementations (mobile/macOS, web, and the Windows/Linux placeholder). Props, events and method names are unchanged.utils/platform_controller*.dart: Android file access, Linux file-URL access, and disposal (Windows/Linux native views, the web iframe session).webview_all*packages are pinned to exactly 1.5.2. They depend on each other with caret constraints, so every one is pinned.prevent_links, event subscriptions,url) go through one ordered path, and every method call waits for the latest one, so aload_request()right afterupdate()sees the newprevent_links.on_console_messagekeeps working in iOS/macOS release builds ([wkwebview] setOnConsoleMessage stops firing in release (AOT) builds after the first garbage collection abandoft/webview_all#61).load_fileandurl=file://open thefile:///URL instead of callingloadFile()([windows] After loadFile(), every loadRequest(), loadHtmlString() and loadFile() from another folder throws PlatformException(method_failed) abandoft/webview_all#60).prevent_linkschecking is on only while the list is non-empty, because Windows restarts every checked navigation as a GET.prevent_linksis also checked for loads the app starts, because Android'sloadUrlskips the navigation delegate.urlno longer breaks every later call.Python (
flet_webview)load_file,clear_cacheandclear_local_storageraiseFletUnsupportedPlatformExceptionon web; the two clear methods would wipe the app's own storage there.scroll_toandscroll_byraise it on macOS.urlloads the new URL;load_request()stays for re-loading the same URL and for POST.on_web_resource_erroralso fires for aurlthat can't be loaded and for a certificate error, which cancels the load.on_scrolltoNoneunsubscribes.Linux client and CI
fullclient only, on Debian 12+ and Ubuntu 22.04+. A newwebview_enabledswitch inci.yml, and--WEBVIEW_…--markers inclient/, keep it out of older distros and out of thelightclient.flet-build-test*.ymlinstalllibwebkit2gtk-4.1-dev, because the test app includesflet-webview.libwebkit2gtk-4.1-0.Docs
flet packand publish/linux now link to it instead of repeating package lists.Breaking changes
All three are in the 1.2.0 changelog.
fullLinux desktop client needslibwebkit2gtk-4.1-0to start, even for apps that don't useWebView. The defaultlightclient doesn't.flet build linuxof an app that includesflet-webviewneedslibwebkit2gtk-4.1-devto build andlibwebkit2gtk-4.1-0to run. So such apps don't run before Debian 12 / Ubuntu 22.04, even if they show the WebView only on other platforms.scroll_to()andscroll_by()raiseFletUnsupportedPlatformExceptionon macOS, which doesn't support them.Testing
A harness that exercises all 19 methods and 8 events, plus per-claim probes for every docstring note, on
webview_all1.5.2:flet-adsflet-adsflet-adsskwasmcanvaskitskwasm: the two failures are the browser's cross-origin limits.canvaskit: the six extra failures are [web] With a scroll handler, dart2js builds never fire onPageFinished for cross-origin pages abandoft/webview_all#55. Whileon_scrollis set, cross-origin pages never fireon_page_ended; unsubscribing ends it. It's documented in theon_scroll,on_page_endedandon_progressnotes.prevent_linksordering,urlchanges, bad URLs, certificate errors, scroll unsubscribe and calls on a removed WebView passes on every platform above, and the harness results stay as in the table. On web, removing a WebView now releases its window listeners right away (checked over CDP across 20 add/remove cycles).flet-adscoexistence: itswebview_flutterandwebview_allcoexist on Android, iOS and macOS.Other upstream issues found along the way: abandoft/webview_all#56, #57 and #58.
Summary by Sourcery
Expand
flet-webviewto Windows and Linux while standardizing its cross-platform implementation and documenting the resulting platform requirements and limitations.New Features:
load_html().webview_allpackage.Bug Fixes:
Enhancements:
Build:
webview_allpackage set to version 1.5.2 and add WebKitGTK build dependencies where required.CI:
Deployment:
Documentation:
Tests:
Chores: