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
docs(zone.js): update docs to enable beforeunload (angular#57881)
In this commit, we update the documentation to reflect the property that allows
enabling the default browser `beforeunload` handling, which was added in a
previous commit.
Additionally, some cosmetic grammar changes have been made in this documentation,
as the previous text had some issues.
Closesangular#52256
PR Closeangular#57881
@@ -4,145 +4,147 @@ Starting from zone.js v0.8.9, you can choose which web API modules you want to p
4
4
the below samples show how to disable some modules. You just need to define a few global variables
5
5
before loading zone.js.
6
6
7
-
```
8
-
<script>
9
-
__Zone_disable_Error = true; // Zone will not patch Error
10
-
__Zone_disable_on_property = true; // Zone will not patch onProperty such as button.onclick
11
-
__Zone_disable_geolocation = true; // Zone will not patch geolocation API
12
-
__Zone_disable_toString = true; // Zone will not patch Function.prototype.toString
13
-
__Zone_disable_blocking = true; // Zone will not patch alert/prompt/confirm
14
-
__Zone_disable_PromiseRejectionEvent = true; // Zone will not patch PromiseRejectionEventHandler
15
-
</script>
16
-
<script src="../bundles/zone.umd.js"></script>
7
+
```html
8
+
<script>
9
+
__Zone_disable_Error =true; // Zone will not patch Error
10
+
__Zone_disable_on_property =true; // Zone will not patch `on` properties such as button.onclick
11
+
__Zone_disable_geolocation =true; // Zone will not patch geolocation API
12
+
__Zone_disable_toString =true; // Zone will not patch Function.prototype.toString
13
+
__Zone_disable_blocking =true; // Zone will not patch alert/prompt/confirm
14
+
__Zone_disable_PromiseRejectionEvent =true; // Zone will not patch PromiseRejectionEventHandler
15
+
</script>
16
+
<scriptsrc="../bundles/zone.umd.js"></script>
17
17
```
18
18
19
19
Below is the full list of currently supported modules.
20
20
21
-
- Common
22
-
23
-
|Module Name|Behavior with zone.js patch|How to disable|
24
-
|--|--|--|
25
-
|Error|stack frames will have the Zone's name information, (By default, Error patch will not be loaded by zone.js)|__Zone_disable_Error = true|
26
-
|toString|Function.toString will be patched to return native version of toString|__Zone_disable_toString = true|
27
-
|ZoneAwarePromise|Promise.then will be patched as Zone aware MicroTask|__Zone_disable_ZoneAwarePromise = true|
28
-
|bluebird|Bluebird will use Zone.scheduleMicroTask as async scheduler. (By default, bluebird patch will not be loaded by zone.js)|__Zone_disable_bluebird = true|
29
-
30
-
- Browser
31
-
32
-
|Module Name|Behavior with zone.js patch|How to disable|
33
-
|--|--|--|
34
-
|on_property|target.onProp will become zone aware target.addEventListener(prop)|__Zone_disable_on_property = true|
35
-
|timers|setTimeout/setInterval/setImmediate will be patched as Zone MacroTask|__Zone_disable_timers = true|
36
-
|requestAnimationFrame|requestAnimationFrame will be patched as Zone MacroTask|__Zone_disable_requestAnimationFrame = true|
37
-
|blocking|alert/prompt/confirm will be patched as Zone.run|__Zone_disable_blocking = true|
38
-
|EventTarget|target.addEventListener will be patched as Zone aware EventTask|__Zone_disable_EventTarget = true|
39
-
|MutationObserver|MutationObserver will be patched as Zone aware operation|__Zone_disable_MutationObserver = true|
40
-
|IntersectionObserver|Intersection will be patched as Zone aware operation|__Zone_disable_IntersectionObserver = true|
41
-
|FileReader|FileReader will be patched as Zone aware operation|__Zone_disable_FileReader = true|
42
-
|canvas|HTMLCanvasElement.toBlob will be patched as Zone aware operation|__Zone_disable_canvas = true|
43
-
|IE BrowserTools check|in IE, browser tool will not use zone patched eventListener|__Zone_disable_IE_check = true|
|XHR|XMLHttpRequest will be patched as Zone aware MacroTask|__Zone_disable_XHR = true|
46
-
|geolocation|navigator.geolocation's prototype will be patched as Zone.run|__Zone_disable_geolocation = true|
47
-
|PromiseRejectionEvent|PromiseRejectEvent will fire when ZoneAwarePromise has unhandled error|__Zone_disable_PromiseRejectionEvent = true|
48
-
|mediaQuery|mediaQuery addListener API will be patched as Zone aware EventTask. (By default, mediaQuery patch will not be loaded by zone.js) |__Zone_disable_mediaQuery = true|
49
-
|notification|notification onProperties API will be patched as Zone aware EventTask. (By default, notification patch will not be loaded by zone.js) |__Zone_disable_notification = true|
50
-
|MessagePort|MessagePort onProperties APIs will be patched as Zone aware EventTask. (By default, MessagePort patch will not be loaded by zone.js) |__Zone_disable_MessagePort = true|
51
-
52
-
- NodeJS
53
-
54
-
|Module Name|Behavior with zone.js patch|How to disable|
| Error | stack frames will have the Zone's name information, (By default, Error patch will not be loaded by zone.js) |\_\_Zone_disable_Error = true |
26
+
| toString | Function.toString will be patched to return native version of toString |\_\_Zone_disable_toString = true |
27
+
| ZoneAwarePromise | Promise.then will be patched as Zone aware MicroTask |\_\_Zone_disable_ZoneAwarePromise = true |
28
+
| bluebird | Bluebird will use Zone.scheduleMicroTask as async scheduler. (By default, bluebird patch will not be loaded by zone.js) |\_\_Zone_disable_bluebird = true |
29
+
30
+
### Browser
31
+
32
+
| Module Name | Behavior with zone.js patch | How to disable |
| on_property | target.onProp will become zone aware target.addEventListener(prop) |\_\_Zone_disable_on_property = true |
35
+
| timers | setTimeout/setInterval/setImmediate will be patched as Zone MacroTask |\_\_Zone_disable_timers = true |
36
+
| requestAnimationFrame | requestAnimationFrame will be patched as Zone MacroTask |\_\_Zone_disable_requestAnimationFrame = true |
37
+
| blocking | alert/prompt/confirm will be patched as Zone.run |\_\_Zone_disable_blocking = true |
38
+
| EventTarget | target.addEventListener will be patched as Zone aware EventTask |\_\_Zone_disable_EventTarget = true |
39
+
| MutationObserver | MutationObserver will be patched as Zone aware operation |\_\_Zone_disable_MutationObserver = true |
40
+
| IntersectionObserver | Intersection will be patched as Zone aware operation |\_\_Zone_disable_IntersectionObserver = true |
41
+
| FileReader | FileReader will be patched as Zone aware operation |\_\_Zone_disable_FileReader = true |
42
+
| canvas | HTMLCanvasElement.toBlob will be patched as Zone aware operation |\_\_Zone_disable_canvas = true |
43
+
| IE BrowserTools check | in IE, browser tool will not use zone patched eventListener |\_\_Zone_disable_IE_check = true |
44
+
| CrossContext check | in webdriver, enable check event listener is cross context |\_\_Zone_enable_cross_context_check = true |
45
+
|`beforeunload`| enable the default `beforeunload` handling behavior, where event handlers return strings to prompt the user |**zone_symbol**enable_beforeunload = true |
46
+
| XHR | XMLHttpRequest will be patched as Zone aware MacroTask |\_\_Zone_disable_XHR = true |
47
+
| geolocation | navigator.geolocation's prototype will be patched as Zone.run |\_\_Zone_disable_geolocation = true |
48
+
| PromiseRejectionEvent | PromiseRejectEvent will fire when ZoneAwarePromise has unhandled error |\_\_Zone_disable_PromiseRejectionEvent = true |
49
+
| mediaQuery | mediaQuery addListener API will be patched as Zone aware EventTask. (By default, mediaQuery patch will not be loaded by zone.js) |\_\_Zone_disable_mediaQuery = true |
50
+
| notification | notification onProperties API will be patched as Zone aware EventTask. (By default, notification patch will not be loaded by zone.js) |\_\_Zone_disable_notification = true |
51
+
| MessagePort | MessagePort onProperties APIs will be patched as Zone aware EventTask. (By default, MessagePort patch will not be loaded by zone.js) |\_\_Zone_disable_MessagePort = true |
52
+
53
+
### Node.js
54
+
55
+
| Module Name | Behavior with zone.js patch | How to disable |
You can also disable specific `on` properties by setting `__Zone_ignore_on_properties` as follows. For example, if you want to disable `window.onmessage` and `HTMLElement.prototype.onclick` from zone.js patching, you can do so like this:
74
+
75
+
```html
76
+
<script>
77
+
__Zone_ignore_on_properties = [
78
+
{
79
+
target:window,
80
+
ignoreProperties: ['message'],
81
+
},
82
+
{
83
+
target:HTMLElement.prototype,
84
+
ignoreProperties: ['click'],
85
+
},
86
+
];
87
+
</script>
88
+
<scriptsrc="../bundles/zone.umd.js"></script>
76
89
```
77
-
<script>
78
-
__Zone_ignore_on_properties = [
79
-
{
80
-
target: window,
81
-
ignoreProperties: ['message']
82
-
}, {
83
-
target: HTMLElement.prototype,
84
-
ignoreProperties: ['click']
85
-
}
86
-
];
87
-
</script>
88
-
<script src="../bundles/zone.umd.js"></script>
90
+
91
+
Excluding `on` properties from being patched means that callbacks will always be invoked within the root context, regardless of where the `on` callback has been set. Even if `onclick` is set within a child zone, the callback will be called inside the root zone:
92
+
93
+
```ts
94
+
Zone.current.fork({ name: 'child' }).run(() => {
95
+
document.body.onclick= () => {
96
+
console.log(Zone.current); // <root>
97
+
};
98
+
});
89
99
```
90
100
91
-
- Error
101
+
You can find more information on adding unpatched events via `addEventListener`, please refer to [UnpatchedEvents](./STANDARD-APIS.md#unpatchedevents).
102
+
103
+
### Error
92
104
93
-
By default, `zone.js/plugins/zone-error` will not be loaded for performance concern.
94
-
This package will provide following functionality.
105
+
By default, `zone.js/plugins/zone-error` will not be loaded for performance reasons.
106
+
This package provides the following functionality:
2. ZoneJsInternalStackFrames: remove zone.js stack from `stackTrace`, and add `zone` information. Without this patch, a lot of `zone.js` invocation stack will be shown
106
-
in stack frames.
116
+
Without the `zone-error` patch, the example above will output `false`. With the patch, the result will be `true`.
107
117
108
-
```
109
-
at zone.run (polyfill.bundle.js: 3424)
110
-
at zoneDelegate.invokeTask (polyfill.bundle.js: 3424)
111
-
at zoneDelegate.runTask (polyfill.bundle.js: 3424)
112
-
at zone.drainMicroTaskQueue (polyfill.bundle.js: 3424)
113
-
at a.b.c (vendor.bundle.js: 12345 <angular>)
114
-
at d.e.f (main.bundle.js: 23456)
115
-
```
118
+
2.**ZoneJsInternalStackFrames:** Remove the zone.js stack from `stackTrace` and add `zone` information. Without this patch, many `zone.js` invocation stacks will be displayed in the stack frames.
116
119
117
-
with this patch, those zone frames will be removed,
118
-
and the zone information `<angular>/<root>` will be added
120
+
```
121
+
at zone.run (polyfill.bundle.js: 3424)
122
+
at zoneDelegate.invokeTask (polyfill.bundle.js: 3424)
123
+
at zoneDelegate.runTask (polyfill.bundle.js: 3424)
124
+
at zone.drainMicroTaskQueue (polyfill.bundle.js: 3424)
125
+
at a.b.c (vendor.bundle.js: 12345 <angular>)
126
+
at d.e.f (main.bundle.js: 23456)
127
+
```
119
128
120
-
```
121
-
at a.b.c (vendor.bundle.js: 12345 <angular>)
122
-
at d.e.f (main.bundle.js: 23456 <root>)
123
-
```
129
+
With this patch, those zone frames will be removed, and the zone information `<angular>/<root>` will be added.
124
130
125
-
The second feature will slow down the `Error` performance, so `zone.js` provide a flag to let you be able to control the behavior.
126
-
The flag is `__Zone_Error_ZoneJsInternalStackFrames_policy`. And the available options is:
131
+
```
132
+
at a.b.c (vendor.bundle.js: 12345 <angular>)
133
+
at d.e.f (main.bundle.js: 23456 <root>)
134
+
```
127
135
128
-
1. default: this is the default one, if you load `zone.js/plugins/zone-error` without
129
-
setting the flag, `default` will be used, and `ZoneJsInternalStackFrames` will be available
130
-
when `new Error()`, you can get a `error.stack` which is `zone stack free`. But this
131
-
will slow down `new Error()` a little bit.
136
+
The second feature may slow down `Error` performance, so `zone.js` provides a flag that allows you to control this behavior.
137
+
The flag is `__Zone_Error_ZoneJsInternalStackFrames_policy`. The available options are:
132
138
133
-
2. disable: this will disable `ZoneJsInternalStackFrames` feature, and if you load
134
-
`zone.js/plugins/zone-error`, you will only get a `wrapped Error` which can handle
135
-
`Error inherit` issue.
139
+
1.**default:** This is the default setting. If you load `zone.js/plugins/zone-error` without setting the flag, `default` will be used. In this case, `ZoneJsInternalStackFrames` will be available when using `new Error()`, allowing you to obtain an `error.stack` that is zone-stack-free. However, this may slightly slow down the performance of new `Error()`.
136
140
137
-
3. lazy: this is a feature to let you be able to get `ZoneJsInternalStackFrames` feature,
138
-
but not impact performance. But as a trade off, you can't get the `zone free stack
139
-
frames` by access `error.stack`. You can only get it by access `error.zoneAwareStack`.
141
+
2.**disable:** This option will disable the `ZoneJsInternalStackFrames` feature. If you load `zone.js/plugins/zone-error`, you will only receive a wrapped `Error`, which can handle the `Error` inheritance issue.
140
142
143
+
3.**lazy:** This feature allows you to access `ZoneJsInternalStackFrames` without impacting performance. However, as a trade-off, you won't be able to obtain the zone-free stack frames via `error.stack`. You can only access them through `error.zoneAwareStack`.
141
144
142
-
- Angular(2+)
145
+
###Angular
143
146
144
-
Angular uses zone.js to manage async operations and decide when to perform change detection. Thus, in Angular,
145
-
the following APIs should be patched, otherwise Angular may not work as expected.
147
+
Angular uses zone.js to manage asynchronous operations and determine when to perform change detection. Therefore, in Angular, the following APIs should be patched; otherwise, Angular may not work as expected:
0 commit comments