Bug 257436

Summary: Image load fail in wkwebview when there is no cache;
Product: WebKit Reporter: hiugunmiao <codingpoorcat>
Component: ImagesAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: achristensen, bfulgham, sabouhallawa, sihui_liu, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: Unspecified   
Attachments:
Description Flags
the demo render image fail in webview.
none
the red area is image which load fail. none

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>