diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 4b97f478..0f044eee 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -836,7 +836,15 @@ class Widget extends EventEmitter { if (!this.parsers[code]) this.parsers[code] = vm.compile(code, defaultScope) - let r = this.parsers[code](jsScope, this.parsersLocalScope) + let r + vm.setWidget(this) + try { + r = this.parsers[code](jsScope, this.parsersLocalScope) + } catch (err) { + vm.setWidget() + throw err + } + vm.setWidget() if (r === undefined) r = '' @@ -852,7 +860,15 @@ class Widget extends EventEmitter { if (!this.parsers[code]) this.parsers[code] = vm.compile('return ' + code.trim(), defaultScope) - let r = this.parsers[code](jsScope, this.parsersLocalScope) + let r + vm.setWidget(this) + try { + r = this.parsers[code](jsScope, this.parsersLocalScope) + } catch (err) { + vm.setWidget() + throw err + } + vm.setWidget() if (r === undefined) r = '' diff --git a/src/client/widgets/vm.js b/src/client/widgets/vm.js index 0c32f403..76948391 100644 --- a/src/client/widgets/vm.js +++ b/src/client/widgets/vm.js @@ -75,7 +75,13 @@ class Vm { registerGlobals() { - this.sandbox.contentWindow.console = console + this.sandbox.contentWindow.console = { + ...console, + log: (msg)=>{ + this.getWidget().log(msg) + } + } + this.sandbox.contentWindow.setTimeout = this.sandbox.contentWindow.setInterval = ()=>{ throw 'setTimeout and setInterval can\'t be used in the JS sandbox'