You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/api/metadata-block.md
+22-11
Original file line number
Diff line number
Diff line change
@@ -137,19 +137,30 @@ Decide when the script will execute.
137
137
138
138
Several values can be set for `@run-at`:
139
139
140
-
-`document-end` <Labelname="default" />
140
+
-`document-start`
141
141
142
-
The script executes when `DOMContentLoaded` is fired. At this time, the basic HTML of the page is ready and other resources like images might still be on the way.
142
+
The userscript executes as early as possible, `document.documentElement` is present, but may be without either `document.head` or `document.body` or both. Other scripts in the page may run earlier, see the note below.
143
143
144
-
-`document-start`
144
+
-`document-body`*(since v2.12.10)*
145
145
146
-
The script executes as soon as possible. There is no guarantee for the script to execute before other scripts in the page.
146
+
The userscript executes after `document.body` appears, possibly with some child elements inside, because detection is asynchronous (using a one-time MutationObserver).
147
+
148
+
-`document-end` <Labelname="default" />
147
149
148
-
Note: in Greasemonkey v3, the script may be ensured to execute even before HTML is loaded, but this is impossible for Violentmonkey as a web extension.
150
+
The userscript executes when `DOMContentLoaded` is fired synchronously. At this time, the basic HTML of the page is ready and other resources like images might still be on the way.
149
151
150
152
-`document-idle`
151
153
152
-
The script executes after `DOMContentLoaded` is fired.
154
+
The userscript executes after `DOMContentLoaded` is fired asynchronously, i.e. after yielding to the previously scheduled callbacks or urgent tasks like rendering. Prefer this mode for scripts that take more than a couple of milliseconds to compile and run (you can see it in devtools performance profiler), so that they don't delay the moment the page becomes usable.
155
+
156
+
When using `document-start` in Violentmonkey ManifestV2 there's a limited method of ensuring the userscript runs before other scripts in the page:
157
+
158
+
* the userscript must use the default [`page` injection mode](#inject-into)
159
+
* the user must enable `Synchronous page mode` (Chrome/Firefox) or `Alternative page mode` (Firefox only, enabled by default) in Violentmonkey's advanced settings;
160
+
* the user didn't change the injection mode to `content` in script's editor or script's settings or in Violentmonkey's settings;
161
+
* the cookies are not explicitly blocked for the site;
162
+
* it's not the incognito mode;
163
+
* Firefox-only: the site doesn't block script elements via its CSP;
153
164
154
165
### @noframes
155
166
@@ -174,16 +185,16 @@ If no `@grant` is present, `@grant none` is assumed.
174
185
```
175
186
176
187
Sandbox is disabled inthis mode, meaning the script can add/modify globals directly without the need to use `unsafeWindow`.
177
-
188
+
178
189
* In case any special API is used, it must be explicitly granted
179
190
180
191
```js
181
192
// @grant GM_getValue
182
193
// @grant GM_setValue
183
194
```
184
-
195
+
185
196
…or for the new`GM.*`API methods *(Since VM2.12.10)*:
186
-
197
+
187
198
```js
188
199
// @grant GM.getValue
189
200
// @grant GM.setValue
@@ -193,12 +204,12 @@ In addition to [GM API](../gm/) the following privileges may be granted:
193
204
194
205
*`// @grant window.close`
195
206
196
-
*Since VM2.6.2*
207
+
*Since VM2.6.2*<br/>
197
208
Allows closing the tab via `window.close()`
198
209
199
210
*`// @grant window.focus`
200
211
201
-
*Since VM2.12.10*
212
+
*Since VM2.12.10*<br/>
202
213
Allows focusing the tab via `window.focus()` even if the user didn't interact with it first.
0 commit comments