When developing a Sketch plugin, chances are you will need some ways to know what is happening when your code is running.
console. Instead, a special method called
log is available.
There are several options to see those logs:
- Open Console.app and look for the sketch logs
- Look at the
skpm logwhich will output the file above (
skpm log -fto stream the logs)
skpm will polyfill
console so that you can use
console.log as usual. In addition to using the
log method behind the scene, it will also forward the logs to
debugger and variable inspection
In Safari, go to
name of your machine >
Automatically Show Web Inspector for JSContexts. And you probably want to enable
Automatically Pause Connecting to JSContext otherwise the inspector will close before you can interact with it (the context is destroyed when the script has finished running).
Now you can use breakpoints in your code, inspect the value of variables at runtime, etc.
Objective-C classes introspection
You can access those information with some introspection methods defined by the bridge. For example:
String(context.document.class()) // MSDocument var mocha = context.document.class().mocha() mocha.properties() // array of MSDocument specific properties defined on a MSDocument instance mocha.propertiesWithAncestors() // array of all the properties defined on a MSDocument instance mocha.instanceMethods() // array of methods defined on a MSDocument instance mocha.instanceMethodsWithAncestors() mocha.classMethods() // array of methods defined on the MSDocument class mocha.classMethodsWithAncestors() mocha.protocols() // array of protocols the MSDocument class inherits from mocha.protocolsWithAncestors()
We created a small Sketch specific tool to help you with debugging your plugins and hopefully make your life easier. It takes the form of a Sketch plugin that you can download here and launch with
cmd + option + j.