diff --git a/CHANGELOG.md b/CHANGELOG.md index b0439e49..24553bed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - scripting - add `setFocusable()` function to change the focusability of the window on the fly (allows reenabling focus temporarely to interact with a text widget using a dedicated toggle button for example) - add `reload()` function + - expose Navigator object with `getNavigator()` ## 1.19.2 diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index dda377ce..29e10db0 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -353,8 +353,15 @@ Run `callback` function as if executed by another that widget matches specified ---- #### `reload(keepState)` -- `keepState` (optional): `true` by default, set to false to discard the client's state. +- `keepState` (optional): `true` by default, set to false to discard the client's state. Reload the client application. Cannot be called from the `onCreate` property. If the event that triggered the script's execution was not initiated by a user interaction, this function will have no effect. + + +---- + +#### `getNavigator()` + +Returns the instance of [Navigator](https://developer.mozilla.org/en-US/docs/Web/API/Navigator). diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index d9e58f36..4ffb30ec 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -549,11 +549,17 @@ class ScriptVm extends Vm { this.sandbox.contentWindow.Image = Image + this.sandbox.contentWindow.getNavigator = ()=>{ + this.checkContext('getNavigator') + return navigator + + } + this.globals = {} for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', - 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus' , 'setFocusable', 'setScroll', 'getScroll', 'toolbar', - 'openUrl', 'getVar', 'setVar', 'runAs', 'reload', 'Image', 'updateCanvas']) { + 'setInterval', 'clearInterval', 'setTimeout', 'cthislearTimeout', 'setFocus', 'unfocus' , 'setFocusable', 'setScroll', 'getScroll', 'toolbar', + 'openUrl', 'getVar', 'setVar', 'runAs', 'reload', 'Image', 'updateCanvas', 'getNavigator']) { this.sanitize(this.sandbox.contentWindow[imports]) this.globals[imports] = true }