Liglo App
Liglo App

Reputation: 3819

How to forward JavaScript console to Cocoa XWebView?

I wonder if it is anyhow possible to display the output of the JavaScript console to the console in the XCode editor. We use XWebView on iOS 8.

Googling seems not to help. I don't really have any idea.

Upvotes: 0

Views: 139

Answers (1)

soflare
soflare

Reputation: 811

There is a new pull request(will be merged soon hopefully) for logging. You can create a object of the new XWVLogging class and load it into your webview object. For example:

let logger = XWVLogging(facility: "webapp")
webview.loadPlugin(logger, namespace: "console.syslog")

After binding the logger to namespace console.syslog, you can call the console.syslog function to send log to Xcode console, and also syslog server of iOS if level is higher than Info(6).

var level = 6;  // Info level, see man page of syslog(1)
console.syslog("Hello from Javascript", level);

Or use the simple notation of level:

console.syslog("+Hello from Javascript");

The leading "+" symbol means Info level. Check the code for other symbols of levels.

However, it doesn't redirect messages from javascript console to Xcode console. You need a wrapper to replace console.log function for doing that. It should be simple.

Any problems or suggestions, please open issues on GitHub.

Upvotes: 1

Related Questions