Bug 257436 - Image load fail in wkwebview when there is no cache;
Summary: Image load fail in wkwebview when there is no cache;
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: All Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-05-27 21:16 PDT by hiugunmiao
Modified: 2023-06-03 21:17 PDT (History)
5 users (show)

See Also:


Attachments
the demo render image fail in webview. (32.77 KB, text/html)
2023-05-27 21:16 PDT, hiugunmiao
no flags Details
the red area is image which load fail. (368.68 KB, image/png)
2023-05-27 21:23 PDT, hiugunmiao
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description hiugunmiao 2023-05-27 21:16:16 PDT
Created attachment 466517 [details]
the demo render image fail in webview.

I tring to render some image in the webview.but if i clear the cache before opening the webview.some image may be load fail(but render correctly after fresh).
there is the swift code 


import UIKit
import WebKit

func clearCache() {
        // 取出cache文件夹目录 缓存文件都在这个目录下
        let cachePath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.cachesDirectory,FileManager.SearchPathDomainMask.userDomainMask, true).first
        // 取出文件夹下所有文件数组
        let fileArr = FileManager.default.subpaths(atPath: cachePath!)
        // 遍历删除
        for file in fileArr! {
            let path = (cachePath! as NSString).appending("/\(file)")
            if FileManager.default.fileExists(atPath: path) {
                do {
                    try FileManager.default.removeItem(atPath: path)
                } catch {
                    
                }
            }
        }
    }
class ViewController: UIViewController, WKNavigationDelegate {
    var webView: WKWebView!
    override func loadView() {
        clearCache()
        webView = WKWebView()
        webView.navigationDelegate = self
        if #available(iOS 16.4, *) {
            webView.isInspectable = true
        } else {
            // Fallback on earlier versions
        }
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let url = URL(string: "my website html")!
        webView.load(URLRequest(url: url))
        webView.allowsBackForwardNavigationGestures = true
    }


}

and the html file is in the attachment;


I tring to find the key code that cause the bug; And i found that some thing can may cause the bug:
1. If i  change the html root font size.
2. Chang the positon of the iamge
3. Change the number of images rendered 
4.Different devices behave differently(same code normal in 14 pro max but fail in se3)

It looks like a lot of factors are causing the problem。So i asked you for help.
Comment 1 hiugunmiao 2023-05-27 21:23:03 PDT
Created attachment 466518 [details]
the red area is image which load fail.
Comment 2 Radar WebKit Bug Importer 2023-06-03 21:17:18 PDT
<rdar://problem/110221382>