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).
1
  • 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? Commented Nov 26, 2014 at 22:06

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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. googleprojectzero.blogspot.com/2019/08/jsc-exploits.html?m=1
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.