1

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).
Clay Bridges
  • 11,602
  • 10
  • 68
  • 118
  • I'm at a loss to see what would cause somebody to downvote this. Is this somehow not a valid question? Is it poorly stated? I'm not trying to hack anybody, this is all within the comforts of my own completely controlled environment. What gives? – Clay Bridges Nov 26 '14 at 22:06

2 Answers2

2

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

Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45
  • 1
    In addition, by exploiting bugs in the implementation of JavaScript, code downloaded from a site can inject code that can call Objective-C. Of course these bugs get patched soon after Apple becomes aware of them, but the fact that people kept finding new ones in the past suggests that people will keep finding new ways to do this in the future. Not that you should do this, but it is good to know for security purposes that your web browser is likely capable of downloading and exectuting essentially arbitrary machine code. https://googleprojectzero.blogspot.com/2019/08/jsc-exploits.html?m=1 – Theodore Norvell Sep 02 '19 at 19:57
1

No. There is no way to do this. The only interface to the client machine is the API which the browser provides.

Michael Fry
  • 1,090
  • 9
  • 12