aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-05-27 23:31:45 +0200
committerLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-07-24 00:23:17 +0000
commit136bbd137f5dd6c428970ab618fcb9afc6af032c (patch)
treef4c81716a0f8c2f584931ec5a0af51960f929adc /docs
parentFixed issue with incorrect icon for air-droid service. (diff)
downloadferdium-recipes-136bbd137f5dd6c428970ab618fcb9afc6af032c.tar.gz
ferdium-recipes-136bbd137f5dd6c428970ab618fcb9afc6af032c.tar.zst
ferdium-recipes-136bbd137f5dd6c428970ab618fcb9afc6af032c.zip
Add documentation for injectJSUnsafe
Diffstat (limited to 'docs')
-rw-r--r--docs/frontend_api.md30
1 files changed, 29 insertions, 1 deletions
diff --git a/docs/frontend_api.md b/docs/frontend_api.md
index c1d35ce..c8e6ba2 100644
--- a/docs/frontend_api.md
+++ b/docs/frontend_api.md
@@ -50,6 +50,34 @@ const focusModeStyles = path.join(__dirname, 'focusmode.css');
50Ferdi.injectCSS(globalStyles, focusModeStyles); 50Ferdi.injectCSS(globalStyles, focusModeStyles);
51``` 51```
52 52
53### injectJSUnsafe(pathToJsFile)
54Injects the contents of one or more JavaScript files into the current webview without context isolation
55
56Ferdi uses context isolation to prevent services from accessing Node.js APIs in the webview.
57If you want to expose objects to the service (eg. via the `window` object) or interact with the Javascript loaded by the service you must do so from a script injected with this method.
58Trying to overwrite properties of the `window` object or other objects or trying to interact with the Javascript loaded by the service from `webview.js` will fail due to context isolation.
59
60The code is executed as if part of the body of a Javascript function, ie. you should modify the `window` object explicitly to expose objects in the global scope.
61
62#### Arguments
631. `string` jsFile
64 * JavaScript files that should be injected. This must be an absolute path to the file
65
66#### Usage
67
68```js
69const path = require('path');
70
71// inject a single css file
72Ferdi.injectJSUnsafe(path.join(__dirname, 'webview-unsafe.js'));
73
74// inject multiple css files
75const globalScripts = path.join(__dirname, 'global.js);
76const focusModeScripts = path.join(__dirname, 'focusmode.js);
77
78Ferdi.injectCSS(globalScripts, focusModeScripts);
79```
80
53### loop(action) 81### loop(action)
54Runs an action every X milliseconds (Ferdi default is currently 1s) 82Runs an action every X milliseconds (Ferdi default is currently 1s)
55 83
@@ -166,4 +194,4 @@ Ferdi.handleDarkMode((isEnabled, helpers) => {
166 helpers.removeDarkModeStyle(); 194 helpers.removeDarkModeStyle();
167 } 195 }
168}) 196})
169``` \ No newline at end of file 197```