{"id":49063,"date":"2025-08-28T17:33:43","date_gmt":"2025-08-28T21:33:43","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=49063"},"modified":"2025-08-28T17:33:43","modified_gmt":"2025-08-28T21:33:43","slug":"swiftui-webview","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2025\/08\/28\/swiftui-webview\/","title":{"rendered":"SwiftUI WebView"},"content":{"rendered":"<p><a href=\"https:\/\/troz.net\/post\/2025\/swiftui-webview\/\">Sarah Reichelt<\/a>:<\/p>\n<blockquote cite=\"https:\/\/troz.net\/post\/2025\/swiftui-webview\/\"><p>In the WWDC video, they demonstrated how to track the navigation events. The code in the video does not work - it doesn&rsquo;t even compile. But after some trial and error, I worked out how to track these events.<\/p><p>[&#8230;]<\/p><p>If you want your <code>WebView<\/code> to load custom pages, create a custom scheme. In my <a href=\"https:\/\/troz.net\/manreader\/\">Man Reader<\/a> app, I use a custom scheme to load HTML versions of man pages, so I decided to try something similar here.<\/p><p>[&#8230;]<\/p><p>In macOS Tahoe 26 beta 7 and Xcode 26 beta 6, this external navigation prints what appears to be a crash log in the console, but the app does not crash.<\/p><p>[&#8230;]<\/p><p>I have included the <code>replaceDisabled(true)<\/code> modifier but it doesn&rsquo;t work in a <code>WebView<\/code>. The modifier doesn&rsquo;t stop the replace interface from appearing, but replacing doesn&rsquo;t actually work[&#8230;]<\/p><p>[&#8230;]<\/p><p>At first, I assumed that <code>page.load()<\/code> required a <code>URL<\/code> or a <code>URLRequest<\/code>, but then I realized that I could also ask it to load a <code>WebPage.BackForwardList.Item<\/code> directly. [&#8230;] I had a problem with the back and forward menus which made me think that the history was not updating correctly. After temporarily re-purposing the refresh button to list the history items, I worked out that history list was correct but the menus were not being updated when the list changed.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/08\/18\/macos-tahoe-26-developer-beta-7\/\">macOS Tahoe 26 Developer Beta 7<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/06\/18\/swiftui-at-wwdc-2025\/\">SwiftUI at WWDC 2025<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/06\/13\/wwdc-2025-links\/\">WWDC 2025 Links<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Sarah Reichelt: In the WWDC video, they demonstrated how to track the navigation events. The code in the video does not work - it doesn&rsquo;t even compile. But after some trial and error, I worked out how to track these events.[&#8230;]If you want your WebView to load custom pages, create a custom scheme. In my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2025-08-28T21:33:45Z","apple_news_api_id":"55fb314d-e01e-41ee-80a8-e21b03919807","apple_news_api_modified_at":"2025-08-28T21:33:46Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AVfsxTeAeQe6AqOIbA5GYBw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,2741,30,2742,71,901,1812,328],"class_list":["post-49063","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-26","tag-mac","tag-macos-tahoe-26","tag-programming","tag-swift-programming-language","tag-swiftui","tag-webkit"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/49063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=49063"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/49063\/revisions"}],"predecessor-version":[{"id":49064,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/49063\/revisions\/49064"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=49063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=49063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=49063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}