2

The WebKit frameworks' WebView class has a property to access the current WebScriptObject. I know that you can invoke JS methods using this object, but is there a way to receive asynchronous JS callback notifications?

I want to render something in the WebView and the script has a callback function when it finishes, but how do I get this notification back to my Cocoa app (without polling a var)?

2 Answers 2

2

I think I figured it out myself.

It should be possible by using the JavaScriptCore framework and by creating an JSObjectRef with JSObjectMakeFunctionWithCallback and pass a C callback function to this constructor.

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

Comments

1

You need to implement the WebScripting protocol which allows you to vend methods of Cocoa classes as functions in the JavaScript environment in the WebView. Have a read of the docs.

You can also use JavaScriptCore as you outlined.

Comments

Your Answer

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