App crashes at WKWebView's 'load' method

If I use Xcode 12.5.1 and an iOS 14 simulator my app runs fine but if I use Xcode 13 the app crashes at the 'load' method of a WKWebView.

if let url = URL(string: stringUrl) {
   webView.load(URLRequest(url: url))
}

On the thread there is a WebKit exception that didn't happen before: "The WKWebView is suspended"

WebKit`-[WKWebView loadRequest:]:
    0x7fff297719e3 <+0>:   pushq  %rbp
    0x7fff297719e4 <+1>:   movq   %rsp, %rbp
    0x7fff297719e7 <+4>:   pushq  %r15
    0x7fff297719e9 <+6>:   pushq  %r14
    0x7fff297719eb <+8>:   pushq  %r12
    0x7fff297719ed <+10>:  pushq  %rbx
    0x7fff297719ee <+11>:  subq   $0x120, %rsp              ; imm = 0x120 
    0x7fff297719f5 <+18>:  movq   %rdx, %r14
    0x7fff297719f8 <+21>:  movq   0x5cf7b751(%rip), %r12    ; WKWebView._page
    0x7fff297719ff <+28>:  movq   (%rdi,%r12), %rbx
    0x7fff29771a03 <+32>:  testq  %rbx, %rbx
    0x7fff29771a06 <+35>:  je     0x7fff29771a41            ; <+94>
    0x7fff29771a08 <+37>:  cmpb   $0x0, 0xc42(%rbx)
    0x7fff29771a0f <+44>:  je     0x7fff29771a43            ; <+96>
    0x7fff29771a11 <+46>:  movq   %rdi, %r15
    0x7fff29771a14 <+49>:  movq   0x5cf79e85(%rip), %rdi    ; (void *)0x00007fff862dbb30: NSException
    0x7fff29771a1b <+56>:  movq   0x5750b20e(%rip), %rax    ; (void *)0x00007fff8a4be2c0: NSInternalInconsistencyException
    0x7fff29771a22 <+63>:  movq   (%rax), %rdx
    0x7fff29771a25 <+66>:  movq   0x5cf732d4(%rip), %rsi    ; "raise:format:"
    0x7fff29771a2c <+73>:  leaq   0x57552e8d(%rip), %rcx    ; @"The WKWebView is suspended"
    0x7fff29771a33 <+80>:  xorl   %eax, %eax
    0x7fff29771a35 <+82>:  callq  *0x5750bddd(%rip)         ; (void *)0x00007fff201803c0: objc_msgSend
    0x7fff29771a3b <+88>:  movq   (%r15,%r12), %rbx
    0x7fff29771a3f <+92>:  jmp    0x7fff29771a43            ; <+96>
    0x7fff29771a41 <+94>:  xorl   %ebx, %ebx
    0x7fff29771a43 <+96>:  leaq   -0x138(%rbp), %r15
    0x7fff29771a4a <+103>: movq   %r15, %rdi
    0x7fff29771a4d <+106>: movq   %r14, %rsi
    0x7fff29771a50 <+109>: callq  0x7fff295d6434            ; WebCore::ResourceRequest::ResourceRequest(NSURLRequest*)
    0x7fff29771a55 <+114>: leaq   -0x28(%rbp), %rdi
    0x7fff29771a59 <+118>: movq   %rbx, %rsi
    0x7fff29771a5c <+121>: movq   %r15, %rdx
    0x7fff29771a5f <+124>: movl   $0x1, %ecx
    0x7fff29771a64 <+129>: xorl   %r8d, %r8d
    0x7fff29771a67 <+132>: callq  0x7fff298b0072            ; WebKit::WebPageProxy::loadRequest(WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy, API::Object*)
->  0x7fff29771a6c <+137>: movq   -0x28(%rbp), %rax
    0x7fff29771a70 <+141>: movq   $0x0, -0x28(%rbp)
    0x7fff29771a78 <+149>: testq  %rax, %rax
    0x7fff29771a7b <+152>: je     0x7fff29771aad            ; <+202>
    0x7fff29771a7d <+154>: movq   0x8(%rax), %rdi
    0x7fff29771a81 <+158>: callq  0x7fff29ccd686            ; symbol stub for: CFMakeCollectable
    0x7fff29771a86 <+163>: movq   %rax, %rdi
    0x7fff29771a89 <+166>: callq  0x7fff29cd3b6c            ; symbol stub for: objc_autorelease
    0x7fff29771a8e <+171>: movq   %rax, %rbx
    0x7fff29771a91 <+174>: movq   -0x28(%rbp), %rax
    0x7fff29771a95 <+178>: movq   $0x0, -0x28(%rbp)
    0x7fff29771a9d <+186>: testq  %rax, %rax
    0x7fff29771aa0 <+189>: je     0x7fff29771aaf            ; <+204>
    0x7fff29771aa2 <+191>: movq   0x8(%rax), %rdi
    0x7fff29771aa6 <+195>: callq  0x7fff29ccd6f8            ; symbol stub for: CFRelease
    0x7fff29771aab <+200>: jmp    0x7fff29771aaf            ; <+204>
    0x7fff29771aad <+202>: xorl   %ebx, %ebx
    0x7fff29771aaf <+204>: movq   -0x30(%rbp), %rdi
    0x7fff29771ab3 <+208>: movq   $0x0, -0x30(%rbp)
    0x7fff29771abb <+216>: testq  %rdi, %rdi
    0x7fff29771abe <+219>: je     0x7fff29771ac5            ; <+226>
    0x7fff29771ac0 <+221>: callq  0x7fff29ccd6f8            ; symbol stub for: CFRelease
    0x7fff29771ac5 <+226>: leaq   -0x138(%rbp), %rdi
    0x7fff29771acc <+233>: callq  0x7fff29503ac4            ; WebCore::ResourceRequestBase::~ResourceRequestBase()
    0x7fff29771ad1 <+238>: movq   %rbx, %rax
    0x7fff29771ad4 <+241>: addq   $0x120, %rsp              ; imm = 0x120 
    0x7fff29771adb <+248>: popq   %rbx
    0x7fff29771adc <+249>: popq   %r12
    0x7fff29771ade <+251>: popq   %r14
    0x7fff29771ae0 <+253>: popq   %r15
    0x7fff29771ae2 <+255>: popq   %rbp
    0x7fff29771ae3 <+256>: retq   
    0x7fff29771ae4 <+257>: movq   %rax, %rbx
    0x7fff29771ae7 <+260>: jmp    0x7fff29771b06            ; <+291>
    0x7fff29771ae9 <+262>: movq   %rax, %rbx
    0x7fff29771aec <+265>: movq   -0x28(%rbp), %rax
    0x7fff29771af0 <+269>: movq   $0x0, -0x28(%rbp)
    0x7fff29771af8 <+277>: testq  %rax, %rax
    0x7fff29771afb <+280>: je     0x7fff29771b06            ; <+291>
    0x7fff29771afd <+282>: movq   0x8(%rax), %rdi
    0x7fff29771b01 <+286>: callq  0x7fff29ccd6f8            ; symbol stub for: CFRelease
    0x7fff29771b06 <+291>: movq   -0x30(%rbp), %rdi
    0x7fff29771b0a <+295>: movq   $0x0, -0x30(%rbp)
    0x7fff29771b12 <+303>: testq  %rdi, %rdi
    0x7fff29771b15 <+306>: je     0x7fff29771b1c            ; <+313>
    0x7fff29771b17 <+308>: callq  0x7fff29ccd6f8            ; symbol stub for: CFRelease
    0x7fff29771b1c <+313>: leaq   -0x138(%rbp), %rdi
    0x7fff29771b23 <+320>: callq  0x7fff29503ac4            ; WebCore::ResourceRequestBase::~ResourceRequestBase()
    0x7fff29771b28 <+325>: movq   %rbx, %rdi
    0x7fff29771b2b <+328>: callq  0x7fff29ccdd5e            ; symbol stub for: _Unwind_Resume

I there something I can do to solve this?

Answered by Shayealdossri in 693158022

Make sure to update to the latest version

Can you show the whole message shown in the debug console? I have not tested enough, but recent iOS are eager to detect more unexpected usages than ever. Do you think of anything unusual in the usage of your WKWebView? Showing more context, including the content of stringUrl or other project settings related to WKWebView may help.

I am also having this error. Xcode 13 iOS 15 simulator fails at loadRequest:

NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url]; [_webView loadRequest:request];

Error shown is:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x10)

Another thread suggested turning off the experimental feature in Safari for GPU rendering and this fixed the crash.

If I use Xcode 12.5.1 and an iOS 14 simulator my app runs fine but if I use Xcode 13 the app crashes at the -load… method of a WKWebView.

Do you see this crash if you run it on a real device?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

OOPer to answer your question, a little bit more on the context:

stringUrl can be an actual string URL as "https://developer.apple.com/", I've tested with this exact URL and it also fails as with any correctly formatted URL

I'm allowing arbitrary loads

This is my Podfile:

platform :ios, '11.0'

pod 'Alamofire'

def common_pods
  # Pods for ####
  pod 'ObjectMapper'
  pod 'MaterialComponents/TextFields'
  pod 'Stripe'
  pod 'SVProgressHUD'
  pod 'BEMCheckBox'
  pod 'CropViewController'
  pod 'BulletinBoard'
  pod 'SDWebImage'
  pod 'Firebase/Analytics'
  pod 'Firebase/Messaging'
  pod 'Firebase/Crashlytics'
  pod 'SendBirdUIKit'
  pod 'IQKeyboardManagerSwift'
  pod 'LaunchDarkly', '~> 5.4'
end

target '####' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for #### prod
  common_pods
end

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
  end
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
    end
  end
end

Thanks for showing more context. But you have not shown that you are using such many pods. As you may know, many pods are well-known as to cause problems at each time iOS or Xcode updates.

I have tried with the exact code and URL you have shown, which causes no issues both on iOS 15 simulator or on an actual device of iOS 15.0.1.

class ViewController: UIViewController {

    @IBOutlet weak var webView: WKWebView!
    
    let stringUrl = "https://developer.apple.com/"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        if let url = URL(string: stringUrl) {
           webView.load(URLRequest(url: url))
        }
    }
}

So, it is very likely that some still hidden parts of your code or any of your pods are causing the issue.

Are you sure you are using WKWebView in a usual manner?

For example, calling load(_:) while the webView is not visible may be considered to be an illegal usage by the recent iOS.

Accepted Answer

Make sure to update to the latest version

Okay thanks for look over and good luck

This is now solved with Xcode 13.1

App crashes at WKWebView's 'load' method
 
 
Q