Wkwebview content size. WKDownloadDelegate 2.
Wkwebview content size innerHeight will return 750, and if my page content overflows the window, window. The closest I can achieve is the code below, which seems to load CSS first (I can see a black screen for a second), and then it gets overwritten by the web content (YouTube. I am updating my iOS app to replace UIWebView with WKWebView. After WKWebView's height exceeds 10000, next time the contentSize changed to box it's height within 10000. scrollView's content size. I'm currently using WKWebView to load some local HTML files for viewing in my iOS app. 1 Moving from UIWebView to WKWebView, I can not figure out how to make the HTML that I am loading using the loadHTMLString function on WKWebView size to fit the view bounds. UIWebView. Add a comment | Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand; OverflowAI GenAI features for Teams; OverflowAPI Train & fine-tune LLMs; Labs The future of collective knowledge sharing; About the company Thanks for your tips! I have a question that how to get a correct contentSize of WKWebView? In my project, I use WKWebView to load some local html string. I've tried the following (and more) from within the delegate method webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) 1. Adjust height of WKWebView frame based on scrollHeight of the webView's content - WKWebViewSizeToFit. My CSS for this part is pretty simple: body { font-family: 'MyCustomFont'; font-size: 15px; } To allow dynamic type I change it to this: body { font-family: 'MyCustomFont'; font: -apple-system-body; } Assume you have a UIKit view that wants to decide about its own size (via intrinsicContentSize or layout constraints, the size might change). Everything builds, top. class ViewController: UIViewController, ARSCNViewDelegate, WKNavigationDelegate { @IBOutlet var sceneView: ARSCNView! I'm trying to show in a WkWebView an html page that I previously downloaded and stored in a String. below is my effort // calling delegate on cell like this let cell = tableView. How to adjust WKWebview's container content height to the webview content? 4 It is possible to intercept requests with WKWebKit, and use URLSession/URLCache directly. loadHTMLString(htmlString, baseURL: nil) Given that one of the major uses for WKWebView is to load remote content, it’s weirdly not just one line of code. The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0). The content itself is loaded from a remote source (via loadHTMLString), so I cannot change the css. width, it gives me a value of 375, and that is obviously far too small, I then try to manually set it to 2000, but no effect. Content of WKWebview in Uitableviewcell is disappearing on dynamic resizing. As example: but expected sth like: swift; macos; swiftui; wkwebview; Can't get WKWebView content height correctly. Then, in viewDidAppear I update the scrollview's content size to the correct value. To autoscale a webpage inside a good old WebView in Swift, all I had to do was: var w:UIWebView w. Hot Network Questions However, when the HTML content inside the WKWebview is large, let's say twice the screen, I suggest adding an observer on the webView. Provide details and share your research! But avoid . Make WKWebView cover the whole screen. canShowMIMEType will be false if the WKWebView realises it can't display the content. If I install app via Xcode with iOS 14, webview works fine, but after I disconnect Xcode and open app directly, webview show content with wrong frame. WKWebView resizes the fonts on web content so that a full-sized web page will fit on the device's form factor. Using KVO for webView. Hidden = true; then set webView. 1. Cordova WKWebView white screen. Because of that i need to calculate the size of WkWebvView content and for that i use evaluateJavaScript(“document. WKWebView not filling container view. Before we start, though, let's make sure you are using the right technology for your application. Underneath the header, there will be a WKWebView for displaying HTML content. 15. Learn how to configure a WKWebView object with a WKWebViewConfiguration object. To expand the WkWebView frame I calculate height from didFinish callback and updating the frame. Hi, How to do this when I am loading webview with URL. You can try to use following ways. Hot Network Questions My app uses WKWebView to present html string. 8 IOS - How to get cached I started porting my iOS app (which works on iPhone and iPad) over to Mac via the Catalyst route but WKWebView is behaving very strange. To fix that issue I have used JavaScript, which works fine in iPhone device but in iPad still UI shows in centre of the Page, check the attached screen shots: My code for WKWebView & Renderer: 1 XAML page you need to set the wkwebview frame size, or use constraints to adjust the size – L33MUR. webView. Follow asked Apr 15, 2021 at 12:37. navigationDelegate = self Sometimes KVO function will called infinitely, try js code below. I use HTML to show the game manual and lore. Forms PCL project that displays posts in the form of a WebView so I add clickable content such as hashtags. 7. contentSize keyPath and then updating your cell size from there. Original: I'm developing an iOS app that has a WKWebView for reading HTML content. Why does -[UIWebView sizeThatFits:] give a larger size than document. 3. How to determine the content size of I am attempting to add a WKWebView to my app that takes up about ~2/3 of the screen (leaving space at the bottom). Q&A for work Trying to create an iOS WKWebView with a size smaller than the screen programmatically. I struggled with it for awhile, the best approach I found was to observe the WKWebView's ScrollView content height, and when the content height repeats itself at the same size then you know it is completely loaded. e 300 * 250 and sometimes it could have a dynamic height. setZoomScale(1. 4. . When the web view decides to call the parent setContentOffset method how do I make sure that it behaviours like it is paying the content? I have an app with a UIWebView and I need to change it into WKWebView. So far I used the st How to get wkwebView content size in swift. Skip to content. 0 When WKWebView embed in a UITableViewCell, secondHalf of WebView will not display. WKWebView inside Scroll View. I'm using WKWebView to load couple of web games into my app. It needs to be lowered by 20px to be below it. WKDownloadDelegate 2. size } // Disable Zoom for WebView func viewForZoomingInScrollView(scrollView UITableViewCell with UIWebview that adjusts height to content size. pdf(configuration:) which was introduced in macOS 12/iOS 15. See Apple's Documentation on Content Rule creation. frame. The example below makes an 'oversized' html document scale to 80% of This works fine on most systems, but on some Macs, resulting WKWebView contents are scaled up about 5% — from 507px to 536px. How to get wkwebView content size in swift. Size Classes and Adaptivity; MKDistanceFormatter; 3D Touch; GameCenter Leaderboards; WKWebView is the centerpiece of the modern WebKit API introduced in iOS 8 & OS X Yosemite. In Safari zooming out results in smaller text and image size but the extra space is actually used. CGSize changedSize = CGSizeFromString(change[@"new"]); CGRect webViewFrame = webView. i have a problem get the WKWebview real content size, any ideas? How to determine the content size of a WKWebView? the answer above do NOT work for me, any ideas? Thanks! When the user clicks a link in your content, the web view acts like a browser and displays the content at that link. webView scrollView]setContentSize:CGSizeMake([ How to determine the content size of a WKWebView? 3. As a bonus, I'll show you how to support dark mode in your web content as well. In our app we are using WKWebView to upload an image and save it trusted content and collaborate around the technologies you use most. Here is a code snippet: @IBOutlet weak var containingView: UIView! var webView: WKWebView! override func you can have a look here as WKWebView don't have a delete which you can use to get content size instead use KVO: KVO example May be it will help you more! Share. Assign the object to the user Content Controller property of your WKWeb View Configuration object before creating your web view. bounces = false webView. The injection of JS into the view to report page size can also be problematic depending on actual page content. How do i change font size in WKWebView swift 5? I'd recommend though to switch to WKWebView since it's recommended also by Apple, and because stringByEvaluatingJavaScript(from:) is blocking (WKWebView provides an async version of this function, and one that also will do the parsing for you, so you can remove the JSON. Hot Network Questions Next step I tried was to find the dimensions of the PDF after it had loaded and set the webview's scrollview content offset to center it: // WKNavigationDelegate func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) I am using WkWebView which works as expected. I have seen other posts like : WKWebView added as Subview is not resized on rotation in Swift. The problem: I am trying to resize the text / content that is being displayed in a WKWebView. In my test app I'm changing size of font via slider and I tried to calculate size of cell but I didn't get correct content size of webView. Assign A WKWeb View object is a platform-native view that you use to incorporate web content seamlessly into your app’s UI. Learn more about Collectives How to get wkwebView content size in swift. I am using . and set an NSLayoutConstraint to make the content to fit the size you want. 10. 0) content size: (834. WkWebView is embedded in a scrollView because i have several other elements (e. Here's my code : var height: CGFloat = 0 { didSet { let frame = CGRect(x: 0, y: 0, width: How to get wkwebView content size in swift. offsetHeight/Width? 1. I a How to determine the content size of a WKWebView? Related. How to determine the content size of a WKWebView? 4. window. 5 via Xcode, web view also show content with wrong frame. Hot Network Questions Can Trump reverse President Joe Biden's pardon for his son? Is there way to increase font size but without horizontal scroll. My App – Top of Page Scrolled = self webView. It does this on MacOS via JavaScript and on iOS by manipulating the UIScrollView associated with the WKWebView to get the full content size and then scrolling the various parts of the content into the visible area and snapshotting it as a grid of image tiles. I’ve tried: Reloading the content (no change) Creating a new WKWebView instance (still shows old Dynamic Type size) Changing the size works at load but am resizing the image dynamically, while doing image does not get fit and it crop as i mentioned earlier. 5, and using same code, it works fine. I can capture all content screenshot of UIWebView by adjust frame of UIScrollView of UIWebView. // There's more! Sometimes the dimensions are still wrong after the rotation has completed , // so In this article, we’ll explore how to create multi-page PDFs from WKWebView content using Swift, // Set the paper size and margins for the page renderer let paperSize = CGSize(width: WKWebView's Intrinsic Content Size issue in iOS 13 beta. Disable Font Scaling on WKWebView. after loading,I wish the webView would fit the size automatic. I have tried giving In this article I'll show you how to write your CSS in order to support dynamic fonts in iOS, so when your user changes the preferred font size in settings you can make sure your app, displaying web content that you control. zero, size: scrollView. Commented Jul 25, 2019 at 13:33. I expecting the content to resize to fit like it does in Safari. width, height: webViewContentHeight)). So initially after loaded the url, web view getting height like "2025" then after clicked on buttons(+ symbol) after displayed popup with additional information means, this time web view scroll content size should be increased with 400 to 500 pixels. body. WKWebView constrains issue when keyboard pops up. Learn more about Collectives Teams. scrollView's superview; adjust I fix it! I dont know, why WKWebView content size not resizing automatically, but we can help him do it. I am trying to set the web view height based on the content height. Don’t worry, UIWebView and WKWebView are similar in nature! Loading a Web Page in WKWebView. Specify custom filters to prevent the webpage from loading restricted content. 8. It’s like having a small Specify custom filters to prevent the webpage from loading restricted content. This leaves the frame at the end of the page after the loop is done. But, sometimes I got a wrong size,the webView's contentSize height longer than the content real height. The only way you could get around this was to set the bounds of your WKWebView to something less than the size of the content. I have a custom WkWebView where I set the height of the view to the size of the html content. However, my main purpose is to make the WKWebView adjust it's height according to it's contents. I'm trying to embed a social post (instagram, Facebook and twitter) into WKWebView, so I'used WKUserScript to calculate height. I looked at all possible delegate functions for WKWebView and nothing else seem to represent the completion of content loading in WKWebView. flexibleWidth, . WKWebView: unable to change font size. evaluateJavaScript("document. About; Content in WKWebview not readjusting its size when device is rotated. Also, the Ionic-maintained WKWebView plugin fork doesn't have this bug, my guess is that they must have seen it and fixed it . {//When the content for the webpage starts arriving, this is I can scroll, down, since the Cell and WebView are the proper size. 0 is the following. The HTML5 games resize perfectly when opening them in safari on my mac, without a problem. I have already tried playing around with adding a viewport to the HTML but I just managed it to scale in widht but not to the height. Each rule is comprised of a trigger and an action. And if a scroll the HTML content the position of the same DIV should be (0, 0). 13. If you have a same problem as mine, you should: Delcare BOOL property . I have searched extensively for a solution but nothing changes the size. 6. So my question is: After a website(any websites on the www) has been loaded up in my iOS webview app how to make the app Programmatically Scroll vertically to any of the contents thats out of view? Is there way to increase font size but without horizontal scroll. Commented Feb 13, 2020 at 6:00 I am trying to re-size the WKWebView dynamically, and it works as it should when the view's height needs to be bigger than the previous height, but if I need to reduce the height, it doesn't adjust. height)]; self. This is a creation example, blocks all image and Style Sheet content, but allows those ended on jpeg by way of I have a WkWebview that is supposed to show the content of HTML emails. 8';", completionHandler: nil) I use [webView. It does resize correctly in Safari though. It’s part of the WebKit framework and WKWebView uses the same browser engine as Safari on iOS and Mac. You can override this behavior by adding "shrink This repo contains an example iOS project that demonstrates how to determine the content size of a WKWebView that loads HTML and local CSS with a custom font. If the contentSize of the page you're rendering is less than the bounds of the WKWebView, the contentSize will be at least the same as the bounds, which results in a blank space. If you want a browser-like experience inside Example. When I switch to portrait mode I get (768x768) dimensions instead of (768x960) which are the correct dimensions. height; i am using WKWebView in table cell and i need to figure out WKWebView content height to manage the table view height but i am able to achieve proper height. Related questions. innerHeight will return 812. I have added this line to each HTML file I need to create a WkWebView with adaptive size. The WKWebView should resize with the enclosing window. I want to change the WKWebView's size using animation but when WKWebView's size changed the webpage loaded goes off to view and its not adjust with the new web view size. Here my code: thanks for helping @IBOutlet weak var view: UIView! @IBOutlet weak var contentView: UIView! @IBOutlet weak var stopButton: UIButton! @IBOutlet weak var skipButton: UIButton! One approach is to increase the WKWebView content size to accommodate larger content. But I think you are right I need to try empty project first. Unable to get exact height of WKWebView. Edit 1: I tried various solutions to resize using the smaller contentSize however the scrollView didn't seem to respond. Add a comment | WKWebView's Intrinsic Content Size issue in iOS 13 beta. I am trying to load HTML content to WKWebView, It does not load properly the same as screen height/width, same code is working fine with UIWebView, How can I fit chart exactly to WKWebView (same as WKWebView size) – AtulParmar. Unfortunately once the WKWebView didFinish loading, changing the frame have no effect on shown content as you can see in picture. For programming the webView I oriented myself on the apple We have a requirement to disable scrolling of web view and show the complete web view content in a table view cell, and only table view should be scrolling not the web view. Scaling content in WKWebView. A detailed explanation If you're using loadHTMLString(_:baseURL:) method on WKWebView to display your content and getting way too big of a height value, a possibly simpler fix than using I have a table view where each cell contains a WKWebView of HTML content. 69. Ideal for displaying HTML markup, styled text content, or complete web pages. 0 . As each one comes back, add the UIWebView to the end of the array. I am migrating my game from UIWebView to WKWebView. Ionic: White space in bottom with wkwebview in IOS 11. A WKWeb View object is a platform-native view that you use to incorporate web content seamlessly into your app’s UI. navigationDelegate = self webView. Safari web inspector not working with cordova in iOS12 and mac OS Mojave. Create a new UIView of the same size as the WKWebView content. Everything . , if a WidthRequest or I'm hosting some 3rd-party content in a WKWebView, and their content doesn't resize correctly on orientation change. The height of the WKWebView increases and since I used dynamic sizing cells, the table cell height will also adjust accordingly. WKWebView add as a subview. image size: (133. Safari's WKWebView Comparison. When I try to get the webView. How to embed WKWebView inside custom UIView properly? 2. addSubview(webView) To navigate the symbols, press Up Arrow, Down Arrow, Left Arrow or Right Arrow In using SwiftUI, the WKWebView loads successfully when implemented within a UIViewRepresentable wrapper. There is a lot of topic about it but none of it worked for me. Is there a workaround to this The UIViewRepresentable equivalent works fine on iOS, but on macOS (natively, not Catalyst), the top content is always cut off. Commented Jul 25, 2017 at 14:17. Once I clean up the solution, I'll come back and update. How to determine the content size of a WKWebView? 3. This works great when I initialize it, but the problem comes when I change the source of the WkWebView to a shorter html. I created demo app for test. Sometime the height is incorrect. However, when I change the orientation of my iPad Pro and thus resize the size of the UICollectionViewCells, the WebView containing the WKWebView also gets resized. How to scale a UIWebview properly. import WebKit struct HTMLView: UIViewRepresentable { let htmlString:String func makeUIView(context:Context)->WKWebView{ return WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { uiView. Get height of UIWebView loaded content. @property(nonatomic, assign) BOOL isWebViewReloaded; and set to NO value in your update view content method Extend WKWebView via a Category with functions that get all the content as image tiles. htmlString!, baseURL: nil) view. Preparing our HTML to scale with the screen density. I would like to use a WKWebView on iOS that always displays text with the exact font size I specify, for example 12px. DevSecOps DevOps CI/CD View all use cases By industry. The WKWebView class can be used to display interactive web content in your iOS app, much like an in-app browser. 5, animated: true) } Now I want it to have only vertical scroll and horizontal content size equal to the frame width. 3 WKWebView add to I'ts must to display some content in the same way as multiline Text() : size of wrapper around the code is larger than expected. At the top of the scroll view, there's going to be a header view. Therefore, we need to create our own version that can detect the content size and trigger a new layout pass as needed. 2. statusBarFrame. Load 7 more related questions Show fewer related questions Sorted by: Reset to default Know someone who can answer? Share a link to this ♪ instrumental hip hop music ♪ ♪ Hello, and welcome to "What's new in WKWebView" I'm Alex Christensen, an engineer on the WebKit team. a VCF file for contacts, or an ICS file for calendar events), I'd like to intercept the link, i. image { I added a wkwebView into a nib. onresize = function() resize itself // according to the correct dimensions. this is my code: this code is the webView's controller WKWebView+contentInset makes content size wrong. 4 "loadHTMLString" height width issue with WKWebView. Because there seems to be no way to add the WKWebView to the storyboard, I added a regular UIView. Initially the content has its size to fit a prescribed width and height. I'm trying to add a little bit of extra height to the content of a UIScrollView that is within a WKWebView after it loads by adjusting the contentSize property. 2 The typical "make 0 pixels high, render webview, query height, set webview height to result" does not work, because if e. – Saravanan. Happy to learn if there is a better approach. By company size. AS shown in below screen shot, the image is not shrinking to webView Size,its original size is 300 If i give sixe of WkWebview to 300 , it comes proper . The amount lost always equals the size of parent views (such as the tab view) and their padding, which indicates that the web view keeps scaling its content to the window size, rather than the view size. height") return nil. The problem is: if the document has less content than the size of the WebView (e. The following steps outline the process: Calculate the total scroll height of the WKWebView content. However, the following logs appear in the Debug area of Xcode Version 13. How to get current width of QWidget inside responsive QVBoxLayout? Hot Network Questions Can I freely choose the spellcasting ability of Magic initiate, or is it tied to the spell list that I chose? When the app starts, the Dynamic Type size setting is correctly applied. Get HTML from WKWebview in Swift. Can't get WKWebView content height correctly. I ended up using this which works. Improve this question. e. Example. So Apple has deprecated WebView in favor of WKWebView, but I'm not seeing a working solution for being able to export (or print) a PDF from the new view type. loading returns false. Works on both MacOS and iOS - cribaudo/Print-All-WKWebView-Content. I am experimenting with replacing a dynamically allocated instance of UIWebView with a WKWebView instance when running under iOS 8 and newer, and I cannot find a way to determine the content size of a WKWebView. For example, the CNContactViewController can be used to display contacts, the EKEventViewController can be While I don't have a solution for the WKWebView not rendering while loading content, I would suggest a different fix to your problem. In this time, width widens I'm not looking for a zoomed in viewport; I'm looking for the entire content to fit and word-wrap like it would with UIWebView. WKWebView is not resizing when content changing. scrollView; create a new container view as webview. For now I'm at the following: It is giving me the wrong window dimensions when the device changes screen orientations on both iPhone and iPad in a WKWebView. I am new to the WKWebView which I am using to load a privacy policy from an url in my application. scalesPageToFit=true I cannot find an equivalent method for a WKWebView, and webpages appear too When this property is true, the WebView should attempt to size itself to the minimum size necessary to fit the web content being displayed. With content size KVO approach, few times I could see a proper height but not all the time. I'm trying to integrate Apple Pencil with a WKWebView. 141 Scaling content in WKWebView. WebView content not scaling correctly. Learn more about In using SwiftUI, the WKWebView loads successfully when implemented within a UIViewRepresentable wrapper. The problem with this solution is that You use WKWebView to display interactive web content in your app. The constraints from the BlueView are correct. Is there any way to enlarge this contents? Please let me know the best approach to solve this problem. frame must contain the whole content to work, I got it by doing yourWebView. Add a comment | 20 I figured out below soultion. This causes my CSS-driven pagination to run over page boundaries, WKWebView: Text rendered at wrong size for certain size ranges when multiple elements use that size in the same document. com), which is not in dark mode. allow, preferences) on the first method, meaning the WKWebView didn't recognise the link as a download, and will try to display it. Once the page renders you will know the size of Usage of WKContentRule to block content on WKWebView - dequin-cl/WKContentRuleExample. Reload();, if it works. Load 7 more related questions Show fewer related questions Sorted by: Reset to default Know someone who can When the WKWebView is the only scroll-able element in the fragment everything is fine and the WebView sends the scroll events to the page. 9. Hi all I'm currently trying to build a view in SwiftUI which is a NavigationView, with a ScrollView inside. Commented Dec 20, Can't get WKWebView content height correctly. Get content Height of WKWebView incorrect. The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to I am loading a . WKWebView is deciding on its own how to render. But I can’t achieve this. blankView. It depends on the type of response I get from server) The initial size of my WkWebView is 300 * 250. 21. Only issue is when I double tap it does not zoom but does focus/ scroll to the area I double tap on. Anybody looking for WKWebView answer, please try the below code: extension YourViewController: WKNavigationDelegate { func webView(_ webView: UiWebview in IPhone resize as per the content size. First, create a Content Rule or a list. I suspect that WKWebView is rerendering after the loop to show the last page's content. You can change the loading view from a page loaded in the webview to a native iOS To navigate the symbols, press Up Arrow, Down Arrow, Left Arrow or Right Arrow I am fairly new to iOS development and I'm using a WKWebView to display a page that plays a video using the Vimeo Player. This is how I setup my WkWebView: webView = WKWebView(frame: self. view. 3 I used WKWebView by follow way: self. In this article I’ve put together 15 of the most common use cases for WKWebView, and provided hands-on Viewport meta tags using "width=device-width" cause the page to scale down to fit content that overflows the viewport bounds. The web view had to be I'm a beginner in Swift programming and would like to add a webView to my app, but I can not set the size of this view properly. However, I can't capture all content screenshot of WKWebView by the same method. – Léo Natan. offsetHeight returns wrong height, Find centralized, trusted content and collaborate around the technologies you use most. Sometimes KVO function will called infinitely, try js code below. backup frame and superview of webview. Here the position of the highlighted DIV should be (0, 123). navigationResponse. (The size will mostly be fixed i. webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen]. scrollView. In heightForRowAtIndexPath you ask the webView for that row what its content size is and return I added UILabel and WKWebView in vertical UIStackview and the distribution is set to fillProportionally. WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init]; CGFloat heightStatusBar = [UIApplication sharedApplication]. I've already encountered this problem in the android version of my app and I fixed that by setting the HeightRequest to 0 before EvaluateJavaScriptAsync. Hot Network Questions In a life-and-death WKWebView's Intrinsic Content Size issue in iOS 13 beta. IOS wkwebview responsive design not fill full screen. A web view supports a full web-browsing experience, and If you turn off your device and turn on it, click the app that has the WKWebview. Create and configure a WKUserContentController object as part of your overall web view setup. WKWebView open in new When the content offset is greater than the size of the content size I want to go to the next page. Commented May 17, 2019 at 3:45. Ilya Ilya. Enterprises Small and medium teams Startups By use case. The size of gif image height = 300. What I want to do is allow users to zoom in The initial size of my WkWebView is 300 * 250. scrollView setContentOffset:CGPointMake(0, pageNumber*webView. I'm using this to "refresh" the content font size and inner layout. I'm trying to implement a "real" fullscreen in App WebView, meaning I want the webcontent to fully go under the notch no matter what. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Instead, you create a URL from a string, method that lets you crop and size the image as needed. I would add the WKWebView as subview of the container view and use the size of the status bar to init the WKWebView with initWithFrame. Stack Overflow. Finally, I want the WKWebView to not be directly scrollable, but fill the outer SwiftUI ScrollView so the header scrolls with it. The html is loading perfect but the content size is too small, I find it difficult to read on small screen size devices like 5s or iPhone SE. This is the current situation I am facing, when framing the WebView to the superviews bounds: The red border is the border of the webView (Also the size of the screen). SwiftUI WKWebView content height issue. Commented Dec 5, 2016 at 15:24. The only way I could show a WKWebView content in my ARKit 3D environment was to load the webView, wait for it to fully load and then take a screenshot of the loaded page and add it to my node. Get HTML by evaluating JavaScript in a WKWebView. It tries to make use of the new async/await functionality (which I most likely ha I want to add a header above the web content of a WKWebView, the web contents will be scrolled over the header as the user scrolls up. The extra space is not used and a margin occurs. This worked for me because I am calling loadHTMLString on local I am working on a Xamarin. To navigate the symbols, press Up Arrow, Down Arrow, Left Arrow or Right Arrow I would like to use a WKWebView on iOS that always displays text with the exact font size I specify, for example 12px. but I'd be very interested in having 'Increase text size' and 'Decrease text size' buttons to help people who need larger text to read. maximumZoomScale = 20 webView. If its' height exceeds 10000 points, WKWebView seems to adjust it's content size. I got it working, but needed the following things: WKWebView must be on the view hierarchy, for example add it to the root view controller, send it to the back, and/or hide it until you need it; yourWebView. However I don't understand how to achieve the same behavior with WKWebView. WKWebView won't open external links. a font-size is defined as 3. Accessing DOM element in WKwebView. zoom = '0. 0. buttons, tableViews). Once the html content is loaded, I am trying to update the height constraint of web view to the scroll height. The important tip turned out to be that UIWebView does not report its size correctly until rendered to the screen. Load 7 more related questions Show fewer related questions Sorted by: Reset to default Know someone who can answer? Share a link to this So, it seems that WebView is able to re-size itself from less content which is previously loaded to more content but unable to re-size itself when the content is less than previously loaded content. WKWebView page height issue on iPhone X. – If I install app via Xcode with iOS 14, webview works fine, but after I disconnect Xcode and open app directly, webview show content with wrong frame. How do i change font size in WKWebView swift 5? I'm trying to show in a WkWebView an html page that I previously downloaded and stored in a String. swift Skip to content All gists Back to GitHub Sign in Sign up I am having serious trouble with taking screenshot of WKWebview content when there is hardware accelerated content (some specific casino games that are running inside iframe). Links in WKWebView randomly not clickable. cancel the navigation, and instead display the content using a specialized view controller. I'ts must to display some content in the same way as multiline Text() : size of wrapper around the code is larger than expected. Here's my code : var height: CGFloat = 0 { didSet { let frame = CGRect(x: 0, y: 0, width: I'm trying to calculate WKWebView content height according to font size. This will help avoid image breaks by ensuring that the entire web content fits within the page boundaries before rendering. How do I scale it to fit my view bounds? It is another view controller, that only includes a WKWebView added as a subview with a button (and gesture) to close the view. The content inside this cell is refreshed via the ViewModel function configure: How to get wkwebView content size in swift. The method I used for capture UIWebView as follow:. 1: [ViewportSizing] maximumViewportInset cannot be larger than frame [ViewportSizing] minimumViewportInset cannot be larger than frame It works when you try to increase content size after webView finish load try this: - (void)webViewDidFinishLoad:(UIWebView *)webView { [[self. For example This resize lag of WKWebView when resizing NSWindow, may be related to using the fullSizeContentView styleMask when initiating the window, or enabling the 'Full Size Content View' in the interface designer. This causes an issue in my app where if you double tap and then minimize the text, it does not minimize it. Improve this Between sizes 22px and 28px, the text is all inexplicably rendered at the same size, and ; And this is the code that adds the WKWebView and loads the content (from within viewDidLoad): WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; WKWebView *webView = 2. Then I "disable" the UIWebView's scrollview by setting it's content size and frame to the size of the entire HTML document. If I build app in iOS 12. “How to calculate WKWebView content height” is published by Bobo Shone in Bobo Shone. style. IOS Swift what am I messing up on in my UIView adding a subview. 17. If it gets higher than this value, the content inside the WKWebView/scrollView gets I have a controller with WKWebView (its inside a container view because WKWebView can't use before iOS 10). The WebView does not load an actual site I am binding the Previously I used the following code to render HTML in a view with swiftUI. If you want the web text in both portrait and landscape to be similar in size to the user's preferred reading size, you need to set it explicitly. Twitter has 100% height and width on the body. If I create new project from Xcode 12. 1: [ViewportSizing] maximumViewportInset cannot be larger than frame [ViewportSizing] minimumViewportInset cannot be larger than frame I would like to inject CSS code to display the web page in dark mode using WebKit on MacOS. webView. Hot Network Questions I would like to inject CSS code to display the web page in dark mode using WebKit on MacOS. size. Find your webview handler. thank you for details! I display PDF in web view, so first of all I load html code, then based on html in WKWebView I generate PDF file which I put to the same WKWevView, so this method called twice: func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!). In a WKWebView, when a user clicks a link that refers to certain file types (e. Healthcare I am using WKWebView in objective c to load my html string that i wrote for my project. contentSize; If you found yourself with some I cannot reproduce this issue in my side. Hidden=false; I can add a WKWebView programmatically to a subview with the code below. Observed behaviour Without the frame argument Safari for iOS seems to fit the web page content perfectly, however. Desired behavior: Using pencil allows you to draw on the webpage with all the fancy PencilKit integrations // Set PKCanvasView to same size as UIScrollView's content size canvasView = PKCanvasView(frame: CGRect(origin: . My WKWebView vs. I need those information when the web view resized with additional content height. With WKWebView, in the simulator, I'll see the sizing I want if I bump up my body text size to 50px instead of 14px. Right now it cuts the Webview off and the rest of the content is crammed up in a I have a WKWebView which loads HTML5 games. gif image inside WKWebview. We've been busy, and we've added a lot of new web technology for you to use in your apps this year. The Find centralized, trusted content and collaborate around the technologies you use most. To disallow navigation, or to customize your web view’s navigation behavior, provide your web view with a navigation delegate — an object that conforms to the WKNavigation Delegate protocol. 0, 988. Asking for help, clarification, or responding to other answers. WKWebView's Intrinsic Content Size issue in iOS 13 beta. How to get values from server side JavaScript and store them in a plist in Swift? Related. For example: /// Some UIKit view that wants to have a . But I cannot find a way to stop it from scaling the fonts based on a lot of different variables, including the orientation of the device and the content in the HTML. Create a WKDownloadDelegate. You could I have an formatted HTML string and want to load it in a wkwebview and scale it so that it fits in height and width of the wkwebviews frame. This worked for me because I am calling loadHTMLString on local I can scroll, down, since the Cell and WebView are the proper size. add webView. The goal was to place this webView in the lower third of the screen (portrait mode), therefore I tried the webView window in the storyboard to look like that and set the constraints. frame = yourWebView. @DougSmith Start with an empty NSMutableArray that your UITableViewController uses to populate its tableView. How to set scale in WKWebview? 7. Navigation Menu Toggle navigation. Something to note is that the URLCache will only store a response IF the size of the response < ~5% of the size of the cache - and I imagine this is the same reason WKWebView doesn't cache responses >= 10MB directly. g. Related. iOS10 WKWebview - evaluateJavaScript("document. Learn more about Collectives (size: CGSize(width: webview. Skip to main content. UIWebView accessing photo library but with multiple selection. width, self. I want to compress the image inside webview to fit inside it. If my page content is 750px high, window. 18. programmatically change WKWebView content size. Load 7 more related questions Show fewer related questions Sorted by: Reset to default Know someone who can answer? Share a link to this Specify custom filters to prevent the webpage from loading restricted content. When setting the magnification to a value less than 1. Auto-sizing should take place only along unspecified dimensions; e. Unfortunately, not the game. Thanks for any advice. Here . height) configuration:theConfiguration]; _webView. 0, 354. offsetHeight returns wrong height, why? 1. To enable users to capture the entire web content as a screenshot, we need to implement a custom solution that scrolls the WKWebView to capture the entire content. Trying to create an iOS WKWebView with a size smaller than the screen programmatically. If I add enough text and it doesn't fit into the WebView - everything gets fine, only vertical scroll I'm trying to embed a social post (instagram, Facebook and twitter) into WKWebView, so I'used WKUserScript to calculate height. If we don’t do anything, our HTML will render very small on our high-density I'm hosting some 3rd-party content in a WKWebView, and their content doesn't resize correctly on orientation change. I now get the html to load but it goes off the right and bottom of my view. I'm trying to resize the WKWebView dynamic HTML content inside UICollectionViewCell by referring a collectionViewCell. I want to create a pdf on macOS with the new WKWebView. Is this a sound approach? This will get called if you answered decisionHandler(. For example, this will produce a 150x50 image from the top-left of the web view: Given a WKWebView showing a web page, how can I get the position (into the frame of my WKWebView) of an HTML element identified by a specific css selector?. dequeueReusableCell(withIdentifier: "TourDetailsOverviewCell", for: indexPath) as! The important tip turned out to be that UIWebView does not report its size correctly until rendered to the screen. flexibleHeight] WKWebView+contentInset makes content size wrong. 1 I changed UIWebView to WKWebView, however, with the same html, trusted content and collaborate around the technologies you use most. I can not set the size from the wkWebView to the contentView (BlueView). To restore the "scroll-under" effect of contentInset, disable the Discussion. only 5 lines of text) - WebView becomes scrollable not only vertical, but also horizontal. I was doing something similar trying to get the content height after load and then sizing the webview's container to be that height. Tried the below approach, but it's not giving the correct content size of the web view if we disable scrolling of the WKWebView. 414. If it does not work, please set webView. the layout hasn't happened yet and you can't get an accurate reading on page size. I've made a Custom webview renderer for iOS where I manually replace a custom WebView with a WKWebView. It seems it not working at the first-time loading. How Can I Fix WKWebView Smaller Content Height Value Problem? 1. WKWebView+contentInset makes content size wrong. 1. addSubview(webView) Prints all the on and offscreen content of a WKWebView and correctly paginates. The caching is very important when it comes to the speed. – Kiran Reddy. When I scroll back to the top, I the text outside my screen is being cut off again, and appears on zoom gesture. contentMode? There is a property called sizeThatFits(CGSize) that attempts to size the content to the provided size. Commented Feb 13, 2020 at 6:00 I've got a simple WKWebView and load a simple HTML-document into it. The problem is that when Dynamic Type size is changed in Settings and you return to the app, the WKWebView does not re-render with the new settings. minimumZoomScale = 1. – Nadi Hassan. width, [UIScreen mainScreen]. scrollHeight”, completionHandler: method. Does missing ScalesPageToFit will be the reason for image crop while resizing in WkWebView? I find that if I use WKWebView with viewport-fit=cover and body : Eventually I found that targeting just the iPhone X sized screen with css media queries for both landscape and portrait did the trick. This approach should work for either UIWebView or WKWebView. Create and configure a WKUser Content Controller object as part of your overall web view setup. 5 webView. trusted content and collaborate around the technologies you use most. A web view supports a full web-browsing experience, and The idea is to set the WKWebView's frame to the desired viewport size, either manually or using autolayout constraints. WKWebView content jumping on load. it actually worked and i managed to save the image in my image path BUT it didnt work if the height exceeds 4 Skip to main content. bounds. See the properties and methods for setting cookies, URL schemes, media playback, data detectors, WKWebView is a powerhouse on iOS, providing high-performance web rendering wherever and whenever you need. Everything works perfectly, except when the webView needs to be with contentInset that is not 0. Specifically for iPad I am showing the web view in a navigation controller. For that, I set the initial web view height as 0. Simply app work like that I changed UIWebView to WKWebView, however, with the same html, trusted content and collaborate around the technologies you use most. 11. When the user clicks a link in your content, the web view acts like a browser and displays the content at that link. frame; webViewFrame. I considered using a pan gesture recognizer. 5. Then in my viewDidAppear method I try and create a WKWebView with the same bounds. Nothing is setup in InterfaceBuilder, I'm doing a subcommunity defined by tags with relevant content and I'm using a UIWebView for displaying content, in the form of an HTML string – not a website, higher than the screen of the iPhone, without needing to scroll in the webView itself, How can i get the current content size of webview? 0. WKWebView content. Font is size smaller in WkWebview compared with UiWebview using same URL. The problem is, WKWebView+contentInset makes content size wrong. Dynamically change size of UIWebview based on content. UIWebView rotation on iPad. 22 WKWebView isn't clickable outside it's contentInset. So when I load the content I set the content size to the available screen height. All the content is too small, it looks like it thinks the monitor is 2 times bigger. autoresizingMask = [. ios; swift; wkwebview; Share. Learn [WKWebView alloc] initWithFrame:CGRectMake(0, 60, self. Because I check it's contentSize property with KVO. I can modify this property, but it somehow keeps changing back to its original size by the time the next layout/display refresh hits. contentSize A WKWebView instance should fill the window corresponding to each document, and the initial size and position of new document windows should be those defined for the NSWindow in the storyboard (480x270 at (196, 240)). Setting contentInset of WKWebView scrollView causes page jump to top. Previously when using UIWebView, I have specified "ScalesPageToFit = false", how to use the same in WkWebview. Sample app WKWebView does not have scalesPageToFit, that's why in WKWebView all content and text sizes displayed small. height) animated:NO] to move the frame up and down the page. 3 WKWebView add to func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { webView. Start your asynchronous requests load the content. Set this property to true to play videos inline, or false to use the native full-screen controller. That is UNTIL the zoom scale reaches a value close to 1. Scrolling not working on WKWebView on iOS 13 beta. 4. how to get proper UIWebView content The content size is okay if it's height is within 10000 points. The problem I am having is the WebView doesn't adjust The problem I am having is the WebView doesn't adjust to the size of its content. 4vh the text will change size when you increase the webview height, invalidating the result of your calculation. Then call reload on the tableView. Suppress WKWebView from scaling content to render at same magnification as UIWebView does. However I can’t seem to get it working properly. contentSize = webView. But when I rotate the device WkWebView is expanding to the screen size but the content inside the webview is not resizing. WkWebview contentOffset not working when settign animated false. height = height; [webView webViewFrame]; Neither of the above approach works. WKWebView add to subview, and set size equal to parent? 1. It's contents consist of predefined HTML string with body. frame) webView. 0) // same size as my WKWebView I want to have the scrollView size match my image. In the UIWebView version, I specified a font size in my CSS, and (as near as I can tell), UIWebView rendered text at that size. I can't get a WKWebView working with both custom fonts and dynamic type at the same time, but it is working separately. Control scroll elasticity in WKWebKit for macOS. stringify() call from the script). // There's more! Sometimes the dimensions are still wrong after the rotation has completed , // so Im starting with a simple app that just shows a web view using WKWebView. WKWebView: document. When adding a video element to an HTML document on iPhone, you must also Have you looked at setting the WKWebView. After writing dynamic content code in cellforItem not getting crashed but dynamic content size not getting called. Getting the final rendered height of a static page in a WKWebView. Thanks Unfortunately, the WebView component doesn't offer a way to size itself based on the content. I started porting my iOS app (which works on iPhone and iPad) over to Mac via the Catalyst route but WKWebView is behaving very strange. This code however, doesn't even help when on the device, so inflating my CSS sizes is not an option In one of my recent projects, I had to use a web view to display an HTML string with local CSS and custom font. Is there a cache size limit I can set, Swift iOS Cache WKWebView content for offline view. loadHTMLString(tipShow. Is there a way to scale up a WKWebView? 1. iOS UIWebView not scaling content. Always. Does anyone have any clue? import UIKit import WebKit class ViewController: UIViewController { @IBOutlet weak var webView: WKWebView! I'm trying to make a screenshot of full webpage rendered in WKWebView: trusted content and collaborate around the technologies you use most. iof iwzab wcprv mdbgai yxcdw lwbxtqs rxcb tclzusj pnsf ptng