javascriptcore

How to include a external library in JavaScriptCore?

无人久伴 提交于 2019-12-01 00:20:26
I am trying to load a external library via JavaScriptCore Specifically I want the end result of this: <script src="fancyLibrary.js" type="text/javascript"></script> But with the syntax of this: JSContext *context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; [context loadExternalJavascriptFileWithName:@"fancyLibrary.js"]; JSValue *fancyFunction = context[@"fancy"]; Is this possible at the current time? I figure I can include the external library in the app bundle and call it from there. It's a matter of loading the library into the context. You just need to use

Why use JavaScriptCore in iOS7 if it can't access a UIWebView's runtime?

我怕爱的太早我们不能终老 提交于 2019-11-30 10:36:55
问题 This is in response to this blog: http://blog.bignerdranch.com/3784-javascriptcore-and-ios-7/ Thoughts from the iOS devs on SO? 回答1: You can get a JSContext from a UIWebView with a key path: UIWebView *webView = [[UIWebView alloc] init]; JSContext *ctx = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; ctx[@"document"][@"body"][@"style"][@"background"] = @"steelblue"; Apple never got around to documenting any of the new JavaScriptCore APIs, so I'm not sure if

Access the JavaScriptCore engine of a UIWebView

主宰稳场 提交于 2019-11-30 07:27:15
I just discovered a new framework available in iOS7: JavaScriptCore. It looks awesome, but how can I access the runtime/context of a UIWebView ? TomSwift There is no official mechanism for this. But there are two approaches I know about to get the JSContext . I probably wouldn't use either in a shipping app. Use KVC to access internal UIWebView properties. Explained in detail in this blog post: http://blog.impathic.com/post/64171814244/true-javascript-uiwebview-integration-in-ios7 JSContext *ctx = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; Add a magic method

How to get JSContext from WKWebView

房东的猫 提交于 2019-11-30 06:27:55
In UIWebView, I can get JSContext through: [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"] The same way doesn't work in WKWebView and app crashes when it arrives this line of code. Is there a way to get JSContext in WKWebView? thanks in advance. You cannot obtain the context, because layout and javascript is handled on another process. Instead, add scripts to your webview configuration, and set your view controller (or another object) as the script message handler. Now, send messages from JavaScript like so: window.webkit.messageHandlers.interOp.postMessage

Trigger objective C method from javascript using JavaScriptCore in iOS 7 in ViewControllers

删除回忆录丶 提交于 2019-11-30 06:24:21
问题 I am loading a url in the webview which has below HTML and javascript function call. Now I am looking into when user touches submit button in webview it should call any method in viewController. Webview should load url(webview delegate) is one approach but is there any new way to get know when javascript function is called by webview should inform viewcontroller or trigger any method in view controller. I am not looking for this solution this we need to - (BOOL)webView:(UIWebView *)webView

Javascript core crash when using YouTube iframe player in UIWebView in iOS 11.3

自闭症网瘾萝莉.ら 提交于 2019-11-30 05:45:10
We have an iOS app with a UIWebView that loads YouTube iframe player to play youtube videos. After iOS 11.3 released we found that there are a lot of javascript core crashes. On Fabric crashlytics the crash stcktrace looks like this Crashed: WebThread 0 JavaScriptCore 0x18aa48298 JSC::JSLock::DropAllLocks::DropAllLocks(JSC::VM&) + 176 1 JavaScriptCore 0x18aa4826c JSC::JSLock::DropAllLocks::DropAllLocks(JSC::VM&) + 132 2 WebCore 0x18b78b794 SendDelegateMessage(NSInvocation*) + 360 3 WebKitLegacy 0x18cea7c68 CallDelegate(void (*)(), WebView*, objc_object*, objc_selector*, objc_object*, objc

Swift blocks not working

依然范特西╮ 提交于 2019-11-30 05:19:39
I've been trying to figure out how to use JavaScriptCore in swift. I'm running into problems however when I have to deal with blocks as arguments, seems like the block is run immediately and the arguments gets the return value of the block. What am I doing wrong? Working Objective C code: JSContext* context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; context[@"test"] = ^(NSString *string) { //code }; What I've tried: 1: var ctx = JSContext(virtualMachine:JSVirtualMachine()) var ctx["test"] = {(string:NSString)->() in /*code*/ } //Gives me "'JSContext' does not

How is an ObjC JS bridge translated?

孤者浪人 提交于 2019-11-29 16:48:55
How does the JavaScriptCore framework translate JavaScript objects into Objective-C objects, and vice versa? Does the bridge use the same binary protocol to communicate for both of the target languages? The Objective-C framework introduced with iOS7 does all the heavy lifting for you. You don't need to think of the objects as the same binary but interpreted differently - the framework performs a copy when converting between ObjC and Javascript. From JSValue.h: // Conversion between Objective-C and JavaScript types. // // When converting between JavaScript values and Objective-C objects a copy

Access the JavaScriptCore engine of a UIWebView

梦想与她 提交于 2019-11-29 08:49:59
问题 I just discovered a new framework available in iOS7: JavaScriptCore. It looks awesome, but how can I access the runtime/context of a UIWebView ? 回答1: There is no official mechanism for this. But there are two approaches I know about to get the JSContext . I probably wouldn't use either in a shipping app. Use KVC to access internal UIWebView properties. Explained in detail in this blog post: http://blog.impathic.com/post/64171814244/true-javascript-uiwebview-integration-in-ios7 JSContext *ctx

Javascript core crash when using YouTube iframe player in UIWebView in iOS 11.3

两盒软妹~` 提交于 2019-11-29 03:56:38
问题 We have an iOS app with a UIWebView that loads YouTube iframe player to play youtube videos. After iOS 11.3 released we found that there are a lot of javascript core crashes. On Fabric crashlytics the crash stcktrace looks like this Crashed: WebThread 0 JavaScriptCore 0x18aa48298 JSC::JSLock::DropAllLocks::DropAllLocks(JSC::VM&) + 176 1 JavaScriptCore 0x18aa4826c JSC::JSLock::DropAllLocks::DropAllLocks(JSC::VM&) + 132 2 WebCore 0x18b78b794 SendDelegateMessage(NSInvocation*) + 360 3