Print using browser console.log();?

Is it possible to print to the browser's console.log(); with a function rather than using system.perspective.print()?

console.log() will print the object and allow browsing via an expandable tree; I was able to get this working from the markdown component but via a script would be very useful. See picture:

No, there's no way to access the richer object printing functionality available in the true browser console. system.perspective.print goes to the 'lowest common denominator' that can be shared between the different possible targets easily.

Somebody like @bmusson might be talked into adding a scripting function that outputs a rich object more directly, but I wouldn't expect this to happen first party anytime soon.

You can do this today with Periscope's runJavaScriptAsync and a simple helper function:

def prettyPrint(obj):
	system.perspective.runJavaScriptAsync('''(obj) => {
		console.log(obj)
	}''', { 'obj': obj })
	
	
thing = {
	'key1': 'value1',
	'key2': [0, 1, 2, 3],
	'key3': {
		'key3.1': 1,
		'key3.2': 2,
		'key3.3': 3
	}
}
	
prettyPrint(thing)

4 Likes