Skip to content

Commit f277d7d

Browse files
committed
doc: add doc for unsafeWindow
1 parent 1e99624 commit f277d7d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

content/api/gm.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: GM_* APIs
2+
title: Privileged APIs
33
date: 2018-04-25 15:15:15
44
path: "/api/gm/"
55
redirect_from:
@@ -14,6 +14,26 @@ import { InfoBox } from '@/components/box';
1414

1515
Violentmonkey APIs are derived from those in Greasemonkey v3, and most of them work the same way, `GM.*` [Greasemonkey v4-compatible](https://wiki.greasespot.net/Greasemonkey_Manual:API) aliases were added in VM2.12.0.
1616

17+
## unsafeWindow
18+
19+
`unsafeWindow` is the actual `window` object of the page.
20+
21+
It is useful when [`@grant`](/api/metadata-block/#grant) is declared with anything other than `none`.
22+
23+
- If `@grant none` is declared, or no `@grant` is declared at all:
24+
25+
Sandbox is disabled, meaning the script can add/modify globals directly without the need to use `unsafeWindow`.
26+
27+
- **window**: the original `window` object
28+
- **unsafeWindow**: the original `window` object
29+
30+
- If any API is declared with `@grant`:
31+
32+
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.
33+
34+
- **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
35+
- **unsafeWindow**: the original `window` object
36+
1737
## GM_*
1838

1939
`GM_*` are a group of special APIs provided by Violentmonkey.

src/common/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ main {
160160
@apply px-1 break-words text-gray-600;
161161
background-color: #f5f2f0;
162162
}
163+
a code {
164+
@apply underline text-inherit;
165+
}
163166

164167
/**
165168
* Inspired by gatsby remark prism - https://www.gatsbyjs.com/plugins/gatsby-remark-prismjs/

0 commit comments

Comments
 (0)