pojala/electrino

Show development tools

gimenete opened this issue · 1 comments

I was trying to implement the window.webContents.openDevTools() method. It's not trivial programmatically but can be open manually if the developerExtrasEnabled flag is set to TRUE.

    WKWebView *webView = [[WKWebView alloc] initWithFrame:window.contentView.bounds configuration:wkConf];
    [webView.configuration.preferences setValue:@(TRUE) forKey:@"developerExtrasEnabled"];

Now you can right click on the page and inspect an element :)

This requires USE_WKWEBVIEW to be set to 1 and I had to modify this code:

- (void)webView:(WebView *)webView didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
{
#if !USE_WKWEBVIEW
    if (frame == self.webView.mainFrame) {
        self.window.title = title;
    }
#endif
}

Because mainFrame doesn't exist on WKWebView.

Btw, why do you want to support both WKWebView and WebView?

Thanks for implementing that!

Actually I don't really want to support both WebKit interfaces... I started out using WKWebView, but then realized that it's not possible to add custom JavaScript objects into the JSContext because WebKit2 runs the browser in a separate process.
(In other words, - (void)webView:didCreateJavaScriptContext:forFrame: only exists for the old WebKit1 WebView.)

I'm still hoping that we might be able to use WKWebView without crippling the Electron browser-side API. Some of those APIs could just be loaded as plain JavaScript, as they don't really require a native implementation (e.g. "process"). For ones that do need to call back to the native side, WebKit2 provides an async message-passing interface (window.webkit.messageHandlers) which could be enough of a building block. I'll need to research this further.