WKNavigationDelegate methods not getting called even though

Hi everyone,

We work on a macOS plugin which then gets loaded into another application. I'm trying to load a webpage in that application through our plugin using a WKWebView & I set my class as the navigationDelegate for the same. I do not receive any callbacks for the WKNavigationDelegate methods. I have debugged & made sure that the navigationDelegate is actually set to my class. Here is a sample code of what I'm doing :

[[NSApplication sharedApplication] runModalForWindow:self.mWindowController.window];

- (void)windowDidLoad
{
    [super windowDidLoad];
    
    [self.window makeKeyAndOrderFront:self];
    [self.window orderFrontRegardless];
    
    if (self.mLoadingView == nil)
    {
        self.mLoadingView = [[LoadingView alloc] initWithFrame:[[self.window contentView] frame]];
    }

    [[self.window contentView] addSubview:self.mLoadingView];
    [self.mLoadingView showLoadingView];
    
    [self.window setLevel:NSMainMenuWindowLevel];
    
    [self loadWebPage];
}

-(void)loadWebPage
{
    [self.mWKWebView setUIDelegate:self];
    [self.mWKWebView setNavigationDelegate:self];
    [self.mWKWebView stopLoading];
    NSURL *lURL = [self samplePageURL];
    WKNavigation *lNavigation = [self.mWKWebView loadRequest:[NSURLRequest requestWithURL:lURL]];
}

- (void)webView:(WKWebView *)pWKWebView
didFinishNavigation:(WKNavigation *)pNavigation
{
    [self removeLoadingview];
    [self.mWKWebView evaluateJavaScript:@"document.body.setAttribute('oncontextmenu', 'event.preventDefault();');" completionHandler:nil];
}

I do not get any calls in the webView:didFinishNavigation: & I also tried other methods like webView:didStartProvisionalNavigation, webView:didFailProvisionalNavigation:withError: etc but did not receive any call in those either. Instead of runModalForWindow: if I use showWindow: on the mWindowController the webpage somehow loads but I still don't get any callbacks & so the loadingview subview is also present. The WKWebView is placed in a storyboard, and I have an IBOutlet connected to it in my class.

Has anyone faced a similar issue or can point me to something I might be missing? All help is appreciated. Thanks in advance.

Are you adding your WKWebView into the view hierarchy in a window? Some callbacks won't happen on a WKWebView unless you do.

Yes the webview is added to my view hierarchy in my storyboard & I have an IBOutlet connected to my class as mentioned above.

WKNavigationDelegate methods not getting called even though
 
 
Q