Cannot detect if user pressed Cancel button on WKWebView sign-in-with-apple pop-up

Viewed 149

I have a WKWebView which loads url of type "https://appleid.apple.com/auth/authorize?response_type=code&client_id=...&redirect_uri=...&response_mode=..." and so on. When it's loaded I see apple auth pop-up like this

I want to close viewController with this webView if user taps Cancel on this pop-up but I can't detect this event. Adding event listener like this is not working:

let config = WKWebViewConfiguration()
let source = "document.addEventListener('AppleIDSignInOnFailure', (error) => { window.webkit.messageHandlers.iosListener.postMessage('Got error'); })"
let script = WKUserScript(source: source, injectionTime: .atDocumentStart, forMainFrameOnly: false)
        
config.userContentController.addUserScript(script)
config.userContentController.add(self, name: "iosListener")
webView = WKWebView(frame: .zero, configuration: config) 

Could anybody please tell me if there is any way to detect if pop-up was closed?

0 Answers
Related