Search code examples
macoscocoawebviewwebkitlinkage

How do I set the WebKit version used by a WebView...?


I'm using WebKit in an OS X app via the JUCE WebBrowserComponent, a lightweight wrapper around Apple's WebView Objective-C class. I'm compiling on OS X 10.12 with a deployment target of 10.7.

The issue I'm having is that on OS X 10.8, the version of WebKit used by the WebView seems to be different to that used by Safari and I can't figure out how the WebKit version is selected or why they are different.

Running otool -L on Safari, gives me:

otool -L /System/Library/PrivateFrameworks/Safari.framework/Versions/A/Safari | grep WebKit
    /System/Library/Frameworks/WebKit.framework/Versions/A/WebKit (compatibility version 1.0.0, current version 536.30.1)
    /System/Library/PrivateFrameworks/WebKit2.framework/Versions/A/WebKit2 (compatibility version 1.0.0, current version 536.30.1)

Running otool -L on the Juce demo gives me:

otool -L JuceDemo | grep WebKit
    /System/Library/Frameworks/WebKit.framework/Versions/A/WebKit (compatibility version 1.0.0, current version 602.2.14)

Firstly, why are the "current version" numbers different, for apparently the same linked framework?

Also, if I point the respective applications at http://browserspy.dk/webkit.php It gives me a AppleWebKit version of 600.8.9 for Safari and a version of 536.30.1 for JUCE Demo.

What accounts for these different version numbers, and how can I configure my application so that my WebView uses the "600.8.9" version of WebKit used by Safari?


Solution

  • otool version

    The current version that otool outputs is the version that was used to link when the app was build.

    Safari, WebKit and everything

    On the latest macOS release Safari uses the system WebKit version. So macOS Sierra 10.12 with Safari 10 uses /System/Library/Frameworks/WebKit.

    Safari also supports older macOS releases. And is updated independently from the system. For example Safari 10 runs on macOS 10.10, 10.11 and 10.12. Now macOS 10.11 was released with Safari 9, but when Safari 10 is installed it uses not the system WebKit. Instead a version in /System/Library/StagedFrameworks/Safari is used.

    Why?

    New major Safari versions not only add shiny new features, and bugs, they sometimes also remove things. Some ill faded -webkit prefixes come to mind. WebKit is part of the SDK which guaranties you that your app will not break on such updates.

    Testing

    Here the version output of a test app from WebView and WKWebView:

    macOS 10.8.5 (12F2560):

    Safari Version 6.2.8 (8537.85.17.9.1)
    WebKit Version 600.8.9

    Cocoa App
    WebView WebKit Version 536.30.1

    macOS 10.9.5 (13F1911):

    Safari Version 9.1.3 (9537.86.7.8)
    WebKit Version 601.7.8

    Cocoa App
    WebView WebKit Version 537.78.2

    macOS 10.10.5 (14F2009):

    Safari Version 10.0.1 (10602.2.14.0.7)
    WebKit Version 602.2.14

    Cocoa App
    WebView WebKit Version 600.8.9
    WKWebView WebKit Version 600.8.9

    macOS 10.11.6 (15G1108):

    Safari Version 10.0.1 (11602.2.14.0.7)
    WebKit Version 602.2.14

    Cocoa App
    WebView WebKit Version 601.7.8
    WKWebView WebKit Version 601.7.8

    Answer

    It is not supported to link your app to the Safari WebKit version.

    You could include your own WebKit build. But I think it's simpler to write your web code for the old version of your deployment target.