diff options
-rw-r--r-- | docs/frontend_api.md | 30 |
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'); | |||
50 | Ferdi.injectCSS(globalStyles, focusModeStyles); | 50 | Ferdi.injectCSS(globalStyles, focusModeStyles); |
51 | ``` | 51 | ``` |
52 | 52 | ||
53 | ### injectJSUnsafe(pathToJsFile) | ||
54 | Injects the contents of one or more JavaScript files into the current webview without context isolation | ||
55 | |||
56 | Ferdi uses context isolation to prevent services from accessing Node.js APIs in the webview. | ||
57 | If 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. | ||
58 | Trying 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 | |||
60 | The 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 | ||
63 | 1. `string` jsFile | ||
64 | * JavaScript files that should be injected. This must be an absolute path to the file | ||
65 | |||
66 | #### Usage | ||
67 | |||
68 | ```js | ||
69 | const path = require('path'); | ||
70 | |||
71 | // inject a single css file | ||
72 | Ferdi.injectJSUnsafe(path.join(__dirname, 'webview-unsafe.js')); | ||
73 | |||
74 | // inject multiple css files | ||
75 | const globalScripts = path.join(__dirname, 'global.js); | ||
76 | const focusModeScripts = path.join(__dirname, 'focusmode.js); | ||
77 | |||
78 | Ferdi.injectCSS(globalScripts, focusModeScripts); | ||
79 | ``` | ||
80 | |||
53 | ### loop(action) | 81 | ### loop(action) |
54 | Runs an action every X milliseconds (Ferdi default is currently 1s) | 82 | Runs 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 | ``` |