Search code examples
javascriptobjective-cmacossafarijavascript-automation

Call Objective-C from Safari javascript?


On OSX (say Yosemite), I'd like a way to call Objective-C from Safari/Javascript. Is there a way to do this?


Not what I'm looking for:

  • embed a WebView/WKWebView in an app
  • Start/control/load Safari from Objective-C
  • use JXA outside of Safari (unless it connects in a way that let's me bridge to Objective-C from inside-Safari javascript).

Solution

  • I came across this reference. So the answer appears to be: yes if you are writing a plugin.

    https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/SafariJSProgTopics/ObjCFromJavaScript.html