Skip to content

Commit f356a2a

Browse files
committed
fix #72: unsafeWindow and sandboxing in VM 2.32+
1 parent 9f826dc commit f356a2a

1 file changed

Lines changed: 2 additions & 16 deletions

File tree

content/pages/api/gm.mdx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,9 @@ Violentmonkey APIs are derived from those in Greasemonkey v3, and most of them w
99

1010
## unsafeWindow
1111

12-
`unsafeWindow` is the actual `window` object of the page.
12+
It's the original `window` object of the webpage that allows reading or modifying global variables, necessary when the script is sandboxed, because its `window` becomes a wrapper that confines modifications like `window.foo = 123` to this script's scope.
1313

14-
It is useful when [`@grant`](/api/metadata-block/#grant) is declared with anything other than `none`.
15-
16-
- If `@grant none` is declared, or no `@grant` is declared at all:
17-
18-
Sandbox is disabled, meaning the script can add/modify globals directly without the need to use `unsafeWindow`.
19-
20-
- **window**: the original `window` object
21-
- **unsafeWindow**: the original `window` object
22-
23-
- If any API is declared with `@grant`:
24-
25-
Sandbox is enabled, meaning the script is executed in an isolated context where `window` is a wrapper of the original `window` object. So you might need `unsafeWindow` if you want to modify a global variable.
26-
27-
- **window**: a wrapper of the original `window` object, adding a new attribute to `window` does not work if it is expected to be accessed by a script in the original world
28-
- **unsafeWindow**: the original `window` object
14+
Sandboxing is enabled by default and disabled only if `@grant none` is specified, just like in Tampermonkey. Note that in older versions of Violentmonkey (before v2.32) sandboxing was also disabled when there were no `@grant` keys.
2915

3016
## GM_*
3117

0 commit comments

Comments
 (0)