Inconsistence between debug and release in the WebBrowserComponent on OSX

I noticed some differences of behaviors between the debug and release version of the WebBrowserComponent on OSX:

  • I can only copy paste, in debug.
  • I have some issues with cookies in release.
  • I made a hack to call javascript on the page but it only works on debug, with Juce 5.4.4 the same hack works on both.

The keyboard command issue has been fixed on develop here:

It sounds like you might have different deployment targets set for your debug and release configurations. WKWebView will be used on macOS 10.11+ whereas the old WebView will be used for deployment targets earlier than this so the differences you are seeing are probably due to the different underlying web views being used.

Can you clarify what issues you are having with cookies?

As for the Javascript issue, it sounds like since the newer web view is stricter about what code can be executed in the browser your previous hack is no longer compatible. What are you doing to execute the Javascript code?

It sounds like you might have different deployment targets set for your debug and release configurations.

oh yes, indeed, thanks.

Can you clarify what issues you are having with cookies?

Sorry I don’t have clear info about that. I’ll let you know when i know more.

As for the Javascript issue, it sounds like since the newer web view is stricter about what code can be executed in the browser your previous hack is no longer compatible. What are you doing to execute the Javascript code?

In the pImpl of WebBrowserComponent i added the following function:

String evaluateJavascriptString(String aJSCode) {
    NSString * lString = [webView stringByEvaluatingJavaScriptFromString:juceStringToNS(aJSCode)];
    return nsStringToJuce(lString);
}

Can I expect the old webview to become depreciated in a near future?

WebView was deprecated by Apple in macOS 10.14 but WKWebView is only available on macOS 10.10+ so we need to keep the old code around for older deployment targets.

In the pImpl of WebBrowserComponent i added the following function:

If you look at the implementation in juce_mac_WebBrowserComponent.mm you’ll see that we use that method for running JS passed to the goToURL() method when the URL starts with javascript:. The equivalent for WKWebView is evaluateJavaScript:.

I noticed but I need a return value from the javascript call.

That should be possible by using the completionHandler in the evaluateJavaScript: method. This isn’t something we want to fully support in the WebBrowserComponent though as most modern web browsers have disabled the JS address bar functionality for security reasons, so you’ll need to update this in your own JUCE modification.

I understand. After a quick research i understood that WKWebView can inject javascript as well so i hope to find a way in the future.