JSCoreBom
JavaScriptCore is missing some things you get used to - setTimeout, XMLHttpRequest, etc. This projects extends JSContext with native implementation of BOM using Objective-C
Install / Use
/learn @artemyarulin/JSCoreBomREADME
JSCoreBom
JavaScriptCore framework on iOS/OSX is missing some things from browser object model you get used to - setTimeout, XMLHttpRequest, etc. Also a lot of libraries requires to have such objects, for example rx.js requires to have setTimeout.
This projects extends JSContext with native implementation of some functions of BOM using Objective-C
How to use it?
Using cocoapods: pod 'JSCoreBom', '~> 1.1.1'.
Whenever you would like to extend JSContext with BOM function just use:
JSContext* context = [[JSContext alloc] init];
[[JSCoreBom shared] extendContext:context];
Then just use it:
[context evaluateScript:@"setTimeout(function(){ console.log('Hi in 5 seconds!')},5000"];
What does it contain?
Name | Description | Status --- | --- | --- setTimeout | Implemented using dispatch_after | Done console.{info,log,debug,warn,error} | Would forward everything to NSLog | Done XmlHTTPRequest | Using NSUrlSession | Proto done
For logger you can specify custom log handler:
[[JSCoreBom shared] extend:context logHandler:^(NSString* logLevel, NSArray* params, NSString* formattedLogEntry) {
if ([logLevel isEqualToString: @"log"])
[MyCustomLogger log:logEntry];
}];
How does it work?
Like Apple on a page 45 said to!
JSContext* context = [[JSContext alloc] init];
context[@"setTimeout"] = ^(JSValue* function, JSValue* timeout) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)([timeout toInt32] * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
[function callWithArguments:@[]];
});
};
Known issues
XMLHttpRequest:
- Always sync call is made using NSURLConnection, not NSUrlSession yet
Related Skills
node-connect
339.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
