2009 01 11Mixing WebView and JavascriptCore
Since Leopard, WebKit's Javascript engine (JavascriptCore) is available as a separate framework for our use. That's how JSCocoa bridges Cocoa into Javascript. And you can now interact with JavascriptCore in a
How ? In
WebView
! This list message on passing a JavaScript callback to a WebKit plug-in details how. That means that we can call any JavascriptCore function in a webpage : create custom Javascript classes, add new properties, call any kind of Javascript. Previously WebScriptObject
somehow filled the role of setting properties and calling scripts, but with some hairy stuff : evaluateWebScript
would return an id
and I recall having trouble deciphering the result. Now we can call JSEvaluateScript
and get a raw JavascriptCore result !How ? In
WebFrame
, the method globalContext will return the JSGlobalContextRef
of the WebView. That's the entry point to JSEvaluateScript
, JSObjectGetProperty
, JSObjectCallAsFunction
and all the other usual JavascriptCore functions. This might come in handy !