View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host;
16  
17  import static org.htmlunit.BrowserVersionFeatures.EVENT_SCROLL_UIEVENT;
18  import static org.htmlunit.BrowserVersionFeatures.JS_WINDOW_SELECTION_NULL_IF_INVISIBLE;
19  import static org.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
20  import static org.htmlunit.javascript.configuration.SupportedBrowser.EDGE;
21  import static org.htmlunit.javascript.configuration.SupportedBrowser.FF;
22  import static org.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR;
23  
24  import java.io.IOException;
25  import java.io.ObjectInputStream;
26  import java.io.Serializable;
27  import java.lang.reflect.Method;
28  import java.net.MalformedURLException;
29  import java.net.URL;
30  import java.util.ArrayList;
31  import java.util.EnumMap;
32  import java.util.HashMap;
33  import java.util.List;
34  import java.util.Map;
35  import java.util.function.Predicate;
36  import java.util.function.Supplier;
37  
38  import org.apache.commons.logging.Log;
39  import org.apache.commons.logging.LogFactory;
40  import org.htmlunit.AlertHandler;
41  import org.htmlunit.BrowserVersion;
42  import org.htmlunit.ConfirmHandler;
43  import org.htmlunit.ElementNotFoundException;
44  import org.htmlunit.Page;
45  import org.htmlunit.PrintHandler;
46  import org.htmlunit.PromptHandler;
47  import org.htmlunit.ScriptException;
48  import org.htmlunit.ScriptResult;
49  import org.htmlunit.SgmlPage;
50  import org.htmlunit.StatusHandler;
51  import org.htmlunit.StorageHolder.Type;
52  import org.htmlunit.TopLevelWindow;
53  import org.htmlunit.WebAssert;
54  import org.htmlunit.WebClient;
55  import org.htmlunit.WebConsole;
56  import org.htmlunit.WebWindow;
57  import org.htmlunit.WebWindowNotFoundException;
58  import org.htmlunit.corejs.javascript.AccessorSlot;
59  import org.htmlunit.corejs.javascript.Context;
60  import org.htmlunit.corejs.javascript.EcmaError;
61  import org.htmlunit.corejs.javascript.Function;
62  import org.htmlunit.corejs.javascript.JavaScriptException;
63  import org.htmlunit.corejs.javascript.NativeConsole.Level;
64  import org.htmlunit.corejs.javascript.NativeObject;
65  import org.htmlunit.corejs.javascript.Scriptable;
66  import org.htmlunit.corejs.javascript.ScriptableObject;
67  import org.htmlunit.corejs.javascript.Slot;
68  import org.htmlunit.corejs.javascript.TopLevel;
69  import org.htmlunit.corejs.javascript.VarScope;
70  import org.htmlunit.css.ComputedCssStyleDeclaration;
71  import org.htmlunit.html.BaseFrameElement;
72  import org.htmlunit.html.DomElement;
73  import org.htmlunit.html.DomNode;
74  import org.htmlunit.html.FrameWindow;
75  import org.htmlunit.html.HtmlAnchor;
76  import org.htmlunit.html.HtmlAttributeChangeEvent;
77  import org.htmlunit.html.HtmlButton;
78  import org.htmlunit.html.HtmlElement;
79  import org.htmlunit.html.HtmlEmbed;
80  import org.htmlunit.html.HtmlForm;
81  import org.htmlunit.html.HtmlImage;
82  import org.htmlunit.html.HtmlInput;
83  import org.htmlunit.html.HtmlMap;
84  import org.htmlunit.html.HtmlObject;
85  import org.htmlunit.html.HtmlPage;
86  import org.htmlunit.html.HtmlSelect;
87  import org.htmlunit.html.HtmlTextArea;
88  import org.htmlunit.javascript.AbstractJavaScriptEngine;
89  import org.htmlunit.javascript.HtmlUnitContextFactory;
90  import org.htmlunit.javascript.HtmlUnitScriptable;
91  import org.htmlunit.javascript.JavaScriptEngine;
92  import org.htmlunit.javascript.PostponedAction;
93  import org.htmlunit.javascript.configuration.JsxClass;
94  import org.htmlunit.javascript.configuration.JsxConstant;
95  import org.htmlunit.javascript.configuration.JsxConstructor;
96  import org.htmlunit.javascript.configuration.JsxFunction;
97  import org.htmlunit.javascript.configuration.JsxGetter;
98  import org.htmlunit.javascript.configuration.JsxSetter;
99  import org.htmlunit.javascript.host.crypto.Crypto;
100 import org.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration;
101 import org.htmlunit.javascript.host.css.MediaQueryList;
102 import org.htmlunit.javascript.host.css.StyleMedia;
103 import org.htmlunit.javascript.host.dom.AbstractList.EffectOnCache;
104 import org.htmlunit.javascript.host.dom.DOMException;
105 import org.htmlunit.javascript.host.dom.Document;
106 import org.htmlunit.javascript.host.dom.Node;
107 import org.htmlunit.javascript.host.dom.Selection;
108 import org.htmlunit.javascript.host.event.Event;
109 import org.htmlunit.javascript.host.event.EventTarget;
110 import org.htmlunit.javascript.host.event.MessageEvent;
111 import org.htmlunit.javascript.host.event.MouseEvent;
112 import org.htmlunit.javascript.host.event.UIEvent;
113 import org.htmlunit.javascript.host.html.DocumentProxy;
114 import org.htmlunit.javascript.host.html.HTMLCollection;
115 import org.htmlunit.javascript.host.html.HTMLDocument;
116 import org.htmlunit.javascript.host.html.HTMLElement;
117 import org.htmlunit.javascript.host.performance.Performance;
118 import org.htmlunit.javascript.host.speech.SpeechSynthesis;
119 import org.htmlunit.javascript.host.xml.XMLDocument;
120 import org.htmlunit.util.StringUtils;
121 import org.htmlunit.util.UrlUtils;
122 import org.htmlunit.xml.XmlPage;
123 
124 /**
125  * JavaScript host object for {@code Window}.
126  *
127  * @author Mike Bowler
128  * @author Chen Jun
129  * @author David K. Taylor
130  * @author Christian Sell
131  * @author Darrell DeBoer
132  * @author Marc Guillemot
133  * @author Dierk Koenig
134  * @author Daniel Gredler
135  * @author David D. Kilzer
136  * @author Chris Erskine
137  * @author Ahmed Ashour
138  * @author Ronald Brill
139  * @author Frank Danek
140  * @author Carsten Steul
141  * @author Colin Alworth
142  * @author Atsushi Nakagawa
143  * @author Sven Strickroth
144  * @author Lai Quang Duong
145  *
146  * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window">MDN Documentation</a>
147  */
148 @JsxClass
149 @SuppressWarnings("PMD.TooManyFields")
150 public class Window extends EventTarget implements WindowOrWorkerGlobalScope, AutoCloseable {
151 
152     private static final Log LOG = LogFactory.getLog(Window.class);
153 
154     /** To be documented. */
155     @JsxConstant({CHROME, EDGE})
156     public static final int TEMPORARY = 0;
157 
158     /** To be documented. */
159     @JsxConstant({CHROME, EDGE})
160     public static final int PERSISTENT = 1;
161 
162     private static final Method GETTER_LENGTH;
163     private static final Method SETTER_LENGTH;
164     private static final Method GETTER_SELF;
165     private static final Method SETTER_SELF;
166     private static final Method GETTER_PARENT;
167     private static final Method SETTER_PARENT;
168     private static final Method GETTER_FRAMES;
169     private static final Method SETTER_FRAMES;
170 
171     static {
172         try {
173             GETTER_LENGTH = Window.class.getDeclaredMethod("jsGetLength");
174             SETTER_LENGTH = Window.class.getDeclaredMethod("jsSetLength", Scriptable.class);
175 
176             GETTER_SELF = Window.class.getDeclaredMethod("jsGetSelf");
177             SETTER_SELF = Window.class.getDeclaredMethod("jsSetSelf", Scriptable.class);
178 
179             GETTER_PARENT = Window.class.getDeclaredMethod("jsGetParent");
180             SETTER_PARENT = Window.class.getDeclaredMethod("jsSetParent", Scriptable.class);
181 
182             GETTER_FRAMES = Window.class.getDeclaredMethod("jsGetFrames");
183             SETTER_FRAMES = Window.class.getDeclaredMethod("jsSetFrames", Scriptable.class);
184         }
185         catch (NoSuchMethodException | SecurityException e) {
186             throw new RuntimeException(e);
187         }
188     }
189 
190     private Scriptable lengthShadow_;
191     private Scriptable selfShadow_;
192     private Scriptable parentShadow_;
193     private Scriptable framesShadow_;
194 
195     private Document document_;
196     private DocumentProxy documentProxy_;
197     private Navigator navigator_;
198     private Object clientInformation_;
199     private WebWindow webWindow_;
200     private WindowProxy windowProxy_;
201     private Screen screen_;
202     private History history_;
203     private Location location_;
204     private Selection selection_;
205     private Event currentEvent_;
206     private String status_ = "";
207     private Map<Class<? extends Scriptable>, Scriptable> prototypes_ = new HashMap<>();
208     private Object controllers_;
209     private Object opener_;
210     private Crypto crypto_;
211     private Scriptable performance_;
212 
213     private final EnumMap<Type, Storage> storages_ = new EnumMap<>(Type.class);
214 
215     private transient List<AnimationFrame> animationFrames_ = new ArrayList<>();
216 
217     private record AnimationFrame(long id_, Function callback_) {
218     }
219 
220     /**
221      * Creates an instance.
222      *
223      * @param cx the current context
224      * @param scope the scope
225      * @param args the arguments
226      * @param ctorObj the function object
227      * @param inNewExpr Is new or not
228      * @return the java object to allow JavaScript to access
229      */
230     @JsxConstructor
231     public static Scriptable jsConstructor(final Context cx, final VarScope scope,
232             final Object[] args, final Function ctorObj, final boolean inNewExpr) {
233         throw JavaScriptEngine.typeError("Illegal constructor");
234     }
235 
236     /**
237      * Restores the transient fields during deserialization.
238      * @param stream the stream to read the object from
239      * @throws IOException if an IO error occurs
240      * @throws ClassNotFoundException if a class is not found
241      */
242     private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
243         stream.defaultReadObject();
244         animationFrames_ = new ArrayList<>();
245     }
246 
247     /**
248      * Returns the prototype object corresponding to the specified HtmlUnit class inside the window scope.
249      * @param jsClass the class whose prototype is to be returned
250      * @return the prototype object corresponding to the specified class inside the specified scope
251      */
252     @Override
253     public Scriptable getPrototype(final Class<? extends HtmlUnitScriptable> jsClass) {
254         return prototypes_.get(jsClass);
255     }
256 
257     /**
258      * Sets the prototypes for HtmlUnit host classes.
259      * @param map a Map of ({@link Class}, {@link Scriptable})
260      */
261     public void setPrototypes(final Map<Class<? extends Scriptable>, Scriptable> map) {
262         prototypes_ = map;
263     }
264 
265     /**
266      * The JavaScript function {@code alert()}.
267      * @param message the message
268      */
269     @JsxFunction
270     public void alert(final Object message) {
271         // use Object as parameter and perform String conversion by ourself
272         // this allows to place breakpoint here and "see" the message object and its properties
273         final String stringMessage = JavaScriptEngine.toString(message);
274         final AlertHandler handler = getWebWindow().getWebClient().getAlertHandler();
275         if (handler == null) {
276             if (LOG.isWarnEnabled()) {
277                 LOG.warn("window.alert(\"" + stringMessage + "\") no alert handler installed");
278             }
279         }
280         else {
281             handler.handleAlert(document_.getPage(), stringMessage);
282         }
283     }
284 
285     /**
286      * Creates a base-64 encoded ASCII string from a string of binary data.
287      * @param stringToEncode string to encode
288      * @return the encoded string
289      */
290     @JsxFunction
291     @Override
292     public String btoa(final String stringToEncode) {
293         return WindowOrWorkerGlobalScopeMixin.btoa(stringToEncode, this);
294     }
295 
296     /**
297      * Decodes a string of data which has been encoded using base-64 encoding.
298      * @param encodedData the encoded string
299      * @return the decoded value
300      */
301     @JsxFunction
302     @Override
303     public String atob(final String encodedData) {
304         return WindowOrWorkerGlobalScopeMixin.atob(encodedData, this);
305     }
306 
307     /**
308      * The JavaScript function {@code confirm}.
309      * @param message the message
310      * @return true if ok was pressed, false if cancel was pressed
311      */
312     @JsxFunction
313     public boolean confirm(final String message) {
314         final ConfirmHandler handler = getWebWindow().getWebClient().getConfirmHandler();
315         if (handler == null) {
316             if (LOG.isWarnEnabled()) {
317                 LOG.warn("window.confirm(\""
318                         + message + "\") no confirm handler installed, simulating the OK button");
319             }
320             return true;
321         }
322         return handler.handleConfirm(document_.getPage(), message);
323     }
324 
325     /**
326      * The JavaScript function {@code prompt}.
327      * @param message the message
328      * @param defaultValue the default value displayed in the text input field
329      * @return the value typed in or {@code null} if the user pressed {@code cancel}
330      */
331     @JsxFunction
332     public String prompt(final String message, final Object defaultValue) {
333         final PromptHandler handler = getWebWindow().getWebClient().getPromptHandler();
334         if (handler == null) {
335             if (LOG.isWarnEnabled()) {
336                 LOG.warn("window.prompt(\"" + message + "\") no prompt handler installed");
337             }
338             return null;
339         }
340         final String defaultText = JavaScriptEngine.isUndefined(defaultValue)
341                                         ? null
342                                         : JavaScriptEngine.toString(defaultValue);
343         return handler.handlePrompt(document_.getPage(), message, defaultText);
344     }
345 
346     /**
347      * Returns the JavaScript property {@code document}.
348      * @return the document
349      */
350     @JsxGetter(propertyName = "document")
351     public DocumentProxy getDocument_js() {
352         return documentProxy_;
353     }
354 
355     /**
356      * Returns the window's current document.
357      * @return the window's current document
358      */
359     public Document getDocument() {
360         return document_;
361     }
362 
363     /**
364      * Returns the current event.
365      * @return the current event, or {@code null} if no event is currently available
366      */
367     @JsxGetter
368     public Object getEvent() {
369         if (currentEvent_ == null) {
370             return JavaScriptEngine.UNDEFINED;
371         }
372         return currentEvent_;
373     }
374 
375     /**
376      * Returns the current event (used internally regardless of the emulation mode).
377      * @return the current event, or {@code null} if no event is currently available
378      */
379     public Event getCurrentEvent() {
380         return currentEvent_;
381     }
382 
383     /**
384      * Sets the current event.
385      * @param event the current event
386      */
387     public void setCurrentEvent(final Event event) {
388         currentEvent_ = event;
389     }
390 
391     /**
392      * Opens a new window.
393      *
394      * @param url when a new document is opened, <i>url</i> is a String that specifies a MIME type for the document.
395      *        When a new window is opened, <i>url</i> is a String that specifies the URL to render in the new window
396      * @param name the name
397      * @param features the features
398      * @param replace whether to replace in the history list or no
399      * @return the newly opened window, or {@code null} if popup windows have been disabled
400      * @see org.htmlunit.WebClientOptions#isPopupBlockerEnabled()
401      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/open">MDN documentation</a>
402      */
403     @JsxFunction
404     public WindowProxy open(final Object url, final Object name, final Object features,
405             final Object replace) {
406         String urlString = null;
407         if (!JavaScriptEngine.isUndefined(url)) {
408             urlString = JavaScriptEngine.toString(url);
409         }
410         String windowName = "";
411         if (!JavaScriptEngine.isUndefined(name)) {
412             windowName = JavaScriptEngine.toString(name);
413         }
414         String featuresString = null;
415         if (!JavaScriptEngine.isUndefined(features)) {
416             featuresString = JavaScriptEngine.toString(features);
417         }
418         final WebClient webClient = getWebWindow().getWebClient();
419 
420         if (webClient.getOptions().isPopupBlockerEnabled()) {
421             LOG.debug("Ignoring window.open() invocation because popups are blocked.");
422             return null;
423         }
424 
425         boolean replaceCurrentEntryInBrowsingHistory = false;
426         if (!JavaScriptEngine.isUndefined(replace)) {
427             replaceCurrentEntryInBrowsingHistory = JavaScriptEngine.toBoolean(replace);
428         }
429         if ((featuresString != null || replaceCurrentEntryInBrowsingHistory) && LOG.isDebugEnabled()) {
430             LOG.debug(
431                    "window.open: features and replaceCurrentEntryInBrowsingHistory "
432                     + "not implemented: url=[" + urlString
433                     + "] windowName=[" + windowName
434                     + "] features=[" + featuresString
435                     + "] replaceCurrentEntry=[" + replaceCurrentEntryInBrowsingHistory
436                     + "]");
437         }
438 
439         // if specified name is the name of an existing window, then hold it
440         if (StringUtils.isEmptyOrNull(urlString) && !StringUtils.isEmptyString(windowName)) {
441             try {
442                 final WebWindow webWindow = webClient.getWebWindowByName(windowName);
443                 return getProxy(webWindow);
444             }
445             catch (final WebWindowNotFoundException ignored) {
446                 // nothing
447             }
448         }
449         final URL newUrl = makeUrlForOpenWindow(urlString);
450         final WebWindow newWebWindow = webClient.openWindow(newUrl, windowName, webWindow_);
451         return getProxy(newWebWindow);
452     }
453 
454     private URL makeUrlForOpenWindow(final String urlString) {
455         if (urlString.isEmpty()) {
456             return UrlUtils.URL_ABOUT_BLANK;
457         }
458 
459         try {
460             final Page page = getWebWindow().getEnclosedPage();
461             if (page != null && page.isHtmlPage()) {
462                 return ((HtmlPage) page).getFullyQualifiedUrl(urlString);
463             }
464             return new URL(urlString);
465         }
466         catch (final MalformedURLException e) {
467             if (LOG.isWarnEnabled()) {
468                 LOG.error("Unable to create URL for openWindow: relativeUrl=[" + urlString + "]", e);
469             }
470             return null;
471         }
472     }
473 
474     /**
475      * Sets a chunk of JavaScript to be invoked at some specified time later.
476      * The invocation occurs only if the window is opened after the delay
477      * and does not contain an other page than the one that originated the setTimeout.
478      *
479      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout">
480      *     MDN web docs</a>
481      *
482      * @param context the JavaScript context
483      * @param scope the scope
484      * @param thisObj the scriptable
485      * @param args the arguments passed into the method
486      * @param function the function
487      * @return the id of the created timer
488      */
489     @JsxFunction
490     public static Object setTimeout(final Context context, final VarScope scope,
491             final Scriptable thisObj, final Object[] args, final Function function) {
492         return WindowOrWorkerGlobalScopeMixin.setTimeout(context, thisObj, args, function);
493     }
494 
495     /**
496      * Queues a microtask to be executed.
497      *
498      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask">
499      *     MDN web docs</a>
500      * @param context the JavaScript context
501      * @param scope the scope
502      * @param thisObj the scriptable
503      * @param args the arguments passed into the method
504      * @param function the function
505      * @return undefined
506      */
507     @JsxFunction
508     public static Object queueMicrotask(final Context context, final VarScope scope,
509             final Scriptable thisObj, final Object[] args, final Function function) {
510         return WindowOrWorkerGlobalScopeMixin.queueMicrotask(thisObj, args);
511     }
512 
513     /**
514      * Sets a chunk of JavaScript to be invoked each time a specified number of milliseconds has elapsed.
515      *
516      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval">
517      *     MDN web docs</a>
518      * @param context the JavaScript context
519      * @param scope the scope
520      * @param thisObj the scriptable
521      * @param args the arguments passed into the method
522      * @param function the function
523      * @return the id of the created interval
524      */
525     @JsxFunction
526     public static Object setInterval(final Context context, final VarScope scope,
527             final Scriptable thisObj, final Object[] args, final Function function) {
528         return WindowOrWorkerGlobalScopeMixin.setInterval(context, thisObj, args, function);
529     }
530 
531     /**
532      * Cancels a one-time timeout that was previously established by a call to
533      * {@link #setTimeout(Context, VarScope, Scriptable, Object[], Function)}.
534      *
535      * <p>If {@code timeoutId} is {@code 0} or negative, this method does nothing,
536      * since valid job IDs are always positive integers. This matches browser behavior
537      * where {@code clearTimeout(0)} is a safe no-op, commonly used when {@code 0}
538      * is employed as a sentinel value to indicate "no active timeout".</p>
539      *
540      * <p>If the given ID does not correspond to any active timeout (e.g. it has
541      * already fired or been cancelled), this method returns silently without
542      * throwing an error, consistent with the HTML Living Standard.</p>
543      *
544      * @param timeoutId the ID of the timeout to cancel, as returned by
545      *        {@link #setTimeout(Context, VarScope, Scriptable, Object[], Function)};
546      *        values of {@code 0} or less are ignored
547      * @see #setTimeout(Context, VarScope, Scriptable, Object[], Function)
548      * @see #clearInterval(int)
549      * @see <a href="https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-cleartimeout">
550      *      HTML Living Standard – clearTimeout</a>
551      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout">
552      *      MDN Web Docs – clearTimeout</a>
553      */
554     @JsxFunction
555     public void clearTimeout(final int timeoutId) {
556         if (timeoutId > 0) {
557             if (LOG.isDebugEnabled()) {
558                 LOG.debug("clearTimeout(" + timeoutId + ")");
559             }
560             getWebWindow().getJobManager().removeJob(timeoutId);
561         }
562     }
563 
564     /**
565      * Cancels a repeating interval that was previously established by a call to
566      * {@link #setInterval(Context, VarScope, Scriptable, Object[], Function)}.
567      *
568      * <p>If {@code intervalID} is {@code 0} or negative, this method does nothing,
569      * since valid job IDs are always positive integers. This matches browser behavior
570      * where {@code clearInterval(0)} is a safe no-op, commonly used when {@code 0}
571      * is employed as a sentinel value to indicate "no active interval".</p>
572      *
573      * <p>If the given ID does not correspond to any active interval (e.g. it has
574      * already fired or been cancelled), this method returns silently without
575      * throwing an error, consistent with the HTML Living Standard.</p>
576      *
577      * @param intervalID the ID of the interval to cancel, as returned by
578      *        {@link #setInterval(Context, VarScope, Scriptable, Object[], Function)};
579      *        values of {@code 0} or less are ignored
580      * @see #setInterval(Context, VarScope, Scriptable, Object[], Function)
581      * @see #clearTimeout(int)
582      * @see <a href="https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-clearinterval">
583      *      HTML Living Standard – clearInterval</a>
584      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/clearInterval">
585      *      MDN Web Docs – clearInterval</a>
586      */
587     @JsxFunction
588     public void clearInterval(final int intervalID) {
589         if (intervalID > 0) {
590             if (LOG.isDebugEnabled()) {
591                 LOG.debug("clearInterval(" + intervalID + ")");
592             }
593             getWebWindow().getJobManager().removeJob(intervalID);
594         }
595     }
596 
597     /**
598      * Returns the JavaScript property {@code navigator}.
599      * @return the navigator
600      */
601     @JsxGetter
602     public Navigator getNavigator() {
603         return navigator_;
604     }
605 
606     /**
607      * Returns the JavaScript property {@code clientInformation}.
608      * @return the client information
609      */
610     @JsxGetter
611     public Object getClientInformation() {
612         if (clientInformation_ != null) {
613             return clientInformation_;
614         }
615         return navigator_;
616     }
617 
618     /**
619      * Sets the {@code clientInformation} property.
620      *
621      * @param clientInformation the new value
622      */
623     @JsxSetter
624     public void setClientInformation(final Object clientInformation) {
625         clientInformation_ = clientInformation;
626     }
627 
628     /**
629      * Returns the window property. This is a synonym for {@code self}.
630      * @return the window property (a reference to <code>this</code>)
631      */
632     @JsxGetter(propertyName = "window")
633     public Window getWindow_js() {
634         return this;
635     }
636 
637     /**
638      * Returns the {@code localStorage} property.
639      * @return the {@code localStorage} property
640      */
641     @JsxGetter
642     public Storage getLocalStorage() {
643         return getStorage(Type.LOCAL_STORAGE);
644     }
645 
646     /**
647      * Returns the {@code sessionStorage} property.
648      * @return the {@code sessionStorage} property
649      */
650     @JsxGetter
651     public Storage getSessionStorage() {
652         return getStorage(Type.SESSION_STORAGE);
653     }
654 
655     /**
656      * Gets the storage of the specified type.
657      * @param storageType the type
658      * @return the storage
659      */
660     public Storage getStorage(final Type storageType) {
661         return storages_.computeIfAbsent(storageType,
662             k -> {
663                 final WebWindow webWindow = getWebWindow();
664                 final Map<String, String> store = webWindow.getWebClient().getStorageHolder().
665                         getStore(storageType, webWindow.getEnclosedPage());
666                 return new Storage(this, store, storageType);
667             }
668         );
669     }
670 
671     /**
672      * Returns the {@code location} property.
673      * @return the {@code location} property
674      */
675     @JsxGetter
676     public Location getLocation() {
677         return location_;
678     }
679 
680     /**
681      * Sets the {@code location} property. This will cause a reload of the window.
682      * @param newLocation the URL of the new content
683      * @throws IOException when location loading fails
684      */
685     @JsxSetter
686     public void setLocation(final String newLocation) throws IOException {
687         location_.setHref(newLocation);
688     }
689 
690     /**
691      * Logs messages to the browser's standard output (stdout). If the browser was started
692      * from a terminal, output sent to dump() will appear in the terminal.
693      * Output from dump() is not sent to the browser's developer tools console.
694      * To log to the developer tools console, use console.log().
695      * <p>
696      * HtmlUnit always uses the WebConsole.
697      * </p>
698      * @param message the message to log
699      */
700     @JsxFunction({FF, FF_ESR})
701     public void dump(final String message) {
702         final WebConsole console = getWebWindow().getWebClient().getWebConsole();
703         console.print(Context.getCurrentContext(), getParentScope(), Level.INFO, new String[] {message}, null);
704     }
705 
706     /**
707      * Invokes all the animation callbacks registered for this window by
708      * calling {@link #requestAnimationFrame(Object)} once.
709      * @return the number of pending animation callbacks
710      */
711     public int animateAnimationsFrames() {
712         final List<AnimationFrame> animationFrames = new ArrayList<>(animationFrames_);
713         animationFrames_.clear();
714 
715         final double now = System.nanoTime() / 1_000_000d;
716         final Object[] args = {now};
717 
718         final WebWindow ww = getWindow().getWebWindow();
719         final JavaScriptEngine jsEngine = (JavaScriptEngine) ww.getWebClient().getJavaScriptEngine();
720 
721         for (final AnimationFrame animationFrame : animationFrames) {
722             jsEngine.callFunction((HtmlPage) ww.getEnclosedPage(),
723                         animationFrame.callback_, getParentScope(), this, args);
724         }
725         return animationFrames_.size();
726     }
727 
728     /**
729      * Add callback to the list of animationFrames.
730      * @param callback the function to call when it's time to update the animation
731      * @return an identification id
732      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame">MDN Doc</a>
733      */
734     @JsxFunction
735     public int requestAnimationFrame(final Object callback) {
736         if (callback instanceof Function function) {
737             final int id = animationFrames_.size();
738             final AnimationFrame animationFrame = new AnimationFrame(id, function);
739             animationFrames_.add(animationFrame);
740             return id;
741         }
742         return -1;
743     }
744 
745     /**
746      * Remove the callback from the list of animationFrames.
747      * @param requestId the ID value returned by the call to window.requestAnimationFrame()
748      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame">MDN Doc</a>
749      */
750     @JsxFunction
751     public void cancelAnimationFrame(final Object requestId) {
752         final int id = (int) JavaScriptEngine.toNumber(requestId);
753 
754         animationFrames_.removeIf(animationFrame -> animationFrame.id_ == id);
755     }
756 
757     /**
758      * Returns the {@code screen} property.
759      * @return the {@code screen} property
760      */
761     @JsxGetter
762     public Screen getScreen() {
763         return screen_;
764     }
765 
766     /**
767      * Returns the {@code history} property.
768      * @return the {@code history} property
769      */
770     @JsxGetter
771     public History getHistory() {
772         return history_;
773     }
774 
775     /**
776      * Returns the {@code external} property.
777      * @return the {@code external} property
778      */
779     @JsxGetter
780     public External getExternal() {
781         final External external = new External();
782         external.setParentScope(getParentScope());
783         external.setPrototype(getPrototype(external.getClass()));
784         return external;
785     }
786 
787     /**
788      * Initializes this window.
789      * @param scope the scope
790      * @param webWindow the web window corresponding to this window
791      * @param pageToEnclose the page that will become the enclosing page
792      */
793     public void initialize(final TopLevel scope, final WebWindow webWindow, final Page pageToEnclose) {
794         webWindow_ = webWindow;
795         webWindow_.setScriptableObject(this);
796 
797         defineProperty(scope, "length", null, GETTER_LENGTH, SETTER_LENGTH, ScriptableObject.READONLY);
798         defineProperty(scope, "self", null, GETTER_SELF, SETTER_SELF, ScriptableObject.READONLY);
799         defineProperty(scope, "parent", null, GETTER_PARENT, SETTER_PARENT, ScriptableObject.READONLY);
800         defineProperty(scope, "frames", null, GETTER_FRAMES, SETTER_FRAMES, ScriptableObject.READONLY);
801 
802         windowProxy_ = new WindowProxy(webWindow_);
803 
804         if (pageToEnclose instanceof XmlPage) {
805             document_ = new XMLDocument();
806         }
807         else {
808             document_ = new HTMLDocument();
809         }
810         document_.setParentScope(scope);
811         document_.setPrototype(getPrototype(document_.getClass()));
812         document_.setWindow(this);
813 
814         if (pageToEnclose instanceof SgmlPage page) {
815             document_.setDomNode(page);
816 
817             if (page.isHtmlPage()) {
818                 final HtmlPage htmlPage = (HtmlPage) page;
819 
820                 htmlPage.addAutoCloseable(this);
821             }
822         }
823 
824         documentProxy_ = new DocumentProxy(webWindow_);
825 
826         navigator_ = new Navigator();
827         navigator_.setParentScope(scope);
828         navigator_.setPrototype(getPrototype(navigator_.getClass()));
829 
830         screen_ = new Screen(getWebWindow().getScreen());
831         screen_.setParentScope(scope);
832         screen_.setPrototype(getPrototype(screen_.getClass()));
833 
834         history_ = new History();
835         history_.setParentScope(scope);
836         history_.setPrototype(getPrototype(history_.getClass()));
837 
838         location_ = new Location();
839         location_.setParentScope(scope);
840         location_.setPrototype(getPrototype(location_.getClass()));
841         location_.initialize(scope, this, pageToEnclose);
842 
843         // like a JS new Object()
844         controllers_ = JavaScriptEngine.newObject(scope);
845 
846         if (webWindow_ instanceof TopLevelWindow window) {
847             final WebWindow opener = window.getOpener();
848             if (opener != null) {
849                 opener_ = opener.getScriptableObject();
850             }
851         }
852     }
853 
854     /**
855      * Initialize the object.
856      * @param enclosedPage the page containing the JavaScript
857      */
858     public void initialize(final Page enclosedPage) {
859         if (enclosedPage != null && enclosedPage.isHtmlPage()) {
860             final HtmlPage htmlPage = (HtmlPage) enclosedPage;
861 
862             // Windows don't have corresponding DomNodes so set the domNode
863             // variable to be the page. If this isn't set then HtmlUnitScriptable.get()
864             // won't work properly
865             setDomNode(htmlPage);
866             clearEventListenersContainer();
867 
868             WebAssert.notNull("document_", document_);
869             document_.setDomNode(htmlPage);
870         }
871     }
872 
873     /**
874      * Initializes the object. Only called for Windows with no contents.
875      */
876     public void initialize() {
877         // Empty.
878     }
879 
880     /**
881      * Returns the value of the {@code top} property.
882      * @return the value of {@code top}
883      */
884     @JsxGetter
885     public Object getTop() {
886         final WebWindow top = getWebWindow().getTopWindow();
887         return top.getScriptableObject();
888     }
889 
890     /**
891      * Returns the value of the {@code opener} property.
892      * @return the value of the {@code opener}, or {@code null} for a top level window
893      */
894     @JsxGetter
895     public Object getOpener() {
896         Object opener = opener_;
897         if (opener instanceof Window window) {
898             opener = window.windowProxy_;
899         }
900         return opener;
901     }
902 
903     /**
904      * Sets the {@code opener} property.
905      * @param newValue the new value
906      */
907     @JsxSetter
908     public void setOpener(final Object newValue) {
909         opener_ = newValue;
910     }
911 
912     /**
913      * Returns the (i)frame in which the window is contained.
914      * @return {@code null} for a top level window
915      */
916     @JsxGetter
917     public HtmlUnitScriptable getFrameElement() {
918         final WebWindow window = getWebWindow();
919         if (window instanceof FrameWindow frameWindow) {
920             return frameWindow.getFrameElement().getScriptableObject();
921         }
922         return null;
923     }
924 
925     /**
926      * Returns the number of frames contained by this window.
927      * @return the number of frames contained by this window
928      */
929     @JsxGetter
930     public Object getLength() {
931         return JavaScriptEngine.UNDEFINED;
932     }
933 
934     /**
935      * Gets the {@code length} property. Setting this shadows the
936      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
937      * @return the shadow value if set otherwise the number of frames
938      */
939     public Object jsGetLength() {
940         if (lengthShadow_ != null) {
941             return lengthShadow_;
942         }
943 
944         final HTMLCollection frames = getFrames();
945         if (frames != null) {
946             return frames.getLength();
947         }
948         return 0;
949     }
950 
951     /**
952      * Sets the {@code length} property. Setting this shadows the
953      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
954      * @param lengthShadow the value to overwrite the defined property value
955      */
956     public void jsSetLength(final Scriptable lengthShadow) {
957         lengthShadow_ = lengthShadow;
958     }
959 
960     /**
961      * Returns the {@code self} property.
962      * @return this
963      */
964     @JsxGetter
965     public Object getSelf() {
966         return JavaScriptEngine.UNDEFINED;
967     }
968 
969     /**
970      * Gets the {@code self} property. Setting this shadows the
971      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
972      * @return the shadow value if set otherwise the number of frames
973      */
974     public Object jsGetSelf() {
975         if (selfShadow_ != null) {
976             return selfShadow_;
977         }
978 
979         return this;
980     }
981 
982     /**
983      * Sets the {@code self} property. Setting this shadows the
984      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
985      * @param selfShadow the value to overwrite the defined property value
986      */
987     public void jsSetSelf(final Scriptable selfShadow) {
988         selfShadow_ = selfShadow;
989     }
990 
991     /**
992      * Returns the value of the {@code parent} property.
993      * @return the value of the {@code parent} property
994      */
995     @JsxGetter
996     public Object getParent() {
997         return JavaScriptEngine.UNDEFINED;
998     }
999 
1000     /**
1001      * Gets the {@code parent} property. Setting this shadows the
1002      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
1003      * @return the shadow value if set otherwise the number of frames
1004      */
1005     public Object jsGetParent() {
1006         if (parentShadow_ != null) {
1007             return parentShadow_;
1008         }
1009 
1010         final WebWindow parent = getWebWindow().getParentWindow();
1011         return parent.getScriptableObject();
1012     }
1013 
1014     /**
1015      * Sets the {@code parent} property. Setting this shadows the
1016      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
1017      * @param parentShadow the value to overwrite the defined property value
1018      */
1019     public void jsSetParent(final Scriptable parentShadow) {
1020         parentShadow_ = parentShadow;
1021     }
1022 
1023     /**
1024      * Returns the value of the {@code frames} property.
1025      * @return the value of the {@code frames} property
1026      */
1027     @JsxGetter(propertyName = "frames")
1028     public Object getFrames_js() {
1029         return JavaScriptEngine.UNDEFINED;
1030     }
1031 
1032     /**
1033      * Gets the {@code frames} property. Setting this shadows the
1034      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
1035      * @return the shadow value if set otherwise the number of frames
1036      */
1037     public Object jsGetFrames() {
1038         if (framesShadow_ != null) {
1039             return framesShadow_;
1040         }
1041 
1042         return this;
1043     }
1044 
1045     /**
1046      * Sets the {@code frames} property. Setting this shadows the
1047      * defined value (see https://webidl.spec.whatwg.org/#Replaceable)
1048      * @param framesShadow the value to overwrite the defined property value
1049      */
1050     public void jsSetFrames(final Scriptable framesShadow) {
1051         framesShadow_ = framesShadow;
1052     }
1053 
1054     /**
1055      * Returns the live collection of frames contained by this window.
1056      * @return the live collection of frames contained by this window
1057      */
1058     private HTMLCollection getFrames() {
1059         final Page page = getWebWindow().getEnclosedPage();
1060         if (page instanceof HtmlPage htmlPage) {
1061             return new HTMLCollectionFrames(htmlPage);
1062         }
1063         return null;
1064     }
1065 
1066     /**
1067      * Returns the WebWindow associated with this Window.
1068      * @return the WebWindow
1069      */
1070     public WebWindow getWebWindow() {
1071         return webWindow_;
1072     }
1073 
1074     /**
1075      * Sets the focus to this element.
1076      */
1077     @JsxFunction
1078     public void focus() {
1079         final WebWindow window = getWebWindow();
1080         window.getWebClient().setCurrentWindow(window);
1081     }
1082 
1083     /**
1084      * Removes focus from this element.
1085      */
1086     @JsxFunction
1087     public void blur() {
1088         LOG.debug("window.blur() not implemented");
1089     }
1090 
1091     /**
1092      * Closes this window.
1093      */
1094     @JsxFunction(functionName = "close")
1095     public void close_js() {
1096         final WebWindow webWindow = getWebWindow();
1097         if (webWindow instanceof TopLevelWindow window) {
1098             window.close();
1099         }
1100         else {
1101             webWindow.getWebClient().deregisterWebWindow(webWindow);
1102         }
1103     }
1104 
1105     /**
1106      * Indicates if this window is closed.
1107      * @return {@code true} if this window is closed
1108      */
1109     @JsxGetter
1110     public boolean isClosed() {
1111         final WebWindow webWindow = getWebWindow();
1112         return !webWindow.getWebClient().containsWebWindow(webWindow);
1113     }
1114 
1115     /**
1116      * Does nothing.
1117      * @param x the horizontal position
1118      * @param y the vertical position
1119      */
1120     @JsxFunction
1121     public void moveTo(final int x, final int y) {
1122         LOG.debug("window.moveTo() not implemented");
1123     }
1124 
1125     /**
1126      * Does nothing.
1127      * @param x the horizontal position
1128      * @param y the vertical position
1129      */
1130     @JsxFunction
1131     public void moveBy(final int x, final int y) {
1132         LOG.debug("window.moveBy() not implemented");
1133     }
1134 
1135     /**
1136      * Does nothing.
1137      * @param width the width offset
1138      * @param height the height offset
1139      */
1140     @JsxFunction
1141     public void resizeBy(final int width, final int height) {
1142         LOG.debug("window.resizeBy() not implemented");
1143     }
1144 
1145     /**
1146      * Does nothing.
1147      * @param width the width of the Window in pixel after resize
1148      * @param height the height of the Window in pixel after resize
1149      */
1150     @JsxFunction
1151     public void resizeTo(final int width, final int height) {
1152         LOG.debug("window.resizeTo() not implemented");
1153     }
1154 
1155     /**
1156      * Scrolls to the specified location on the page.
1157      * @param x the horizontal position to scroll to
1158      * @param y the vertical position to scroll to
1159      */
1160     @JsxFunction
1161     public void scroll(final Scriptable x, final Scriptable y) {
1162         scrollTo(x, y);
1163     }
1164 
1165     /**
1166      * Scrolls the window content the specified distance.
1167      * @param x the horizontal distance to scroll by
1168      * @param y the vertical distance to scroll by
1169      */
1170     @JsxFunction
1171     public void scrollBy(final Scriptable x, final Scriptable y) {
1172         final HTMLElement body = document_.getBody();
1173         if (body != null) {
1174             int xOff = 0;
1175             int yOff = 0;
1176             if (y != null) {
1177                 xOff = JavaScriptEngine.toInt32(x);
1178                 yOff = JavaScriptEngine.toInt32(y);
1179             }
1180             else {
1181                 if (!(x instanceof NativeObject)) {
1182                     throw JavaScriptEngine.typeError("eee");
1183                 }
1184                 if (x.has("left", x)) {
1185                     xOff = JavaScriptEngine.toInt32(x.get("left", x));
1186                 }
1187                 if (x.has("top", x)) {
1188                     yOff = JavaScriptEngine.toInt32(x.get("top", x));
1189                 }
1190             }
1191 
1192             body.setScrollLeft(body.getScrollLeft() + xOff);
1193             body.setScrollTop(body.getScrollTop() + yOff);
1194 
1195             fireScrollEvent(body);
1196         }
1197 
1198         fireScrollEvent(document_);
1199     }
1200 
1201     private void fireScrollEvent(final Node node) {
1202         final Event event;
1203         if (getBrowserVersion().hasFeature(EVENT_SCROLL_UIEVENT)) {
1204             event = new UIEvent(node, Event.TYPE_SCROLL);
1205         }
1206         else {
1207             event = new Event(node, Event.TYPE_SCROLL);
1208             event.setCancelable(false);
1209         }
1210         node.fireEvent(event);
1211     }
1212 
1213     /**
1214      * Scrolls the window content down by the specified number of lines.
1215      * @param lines the number of lines to scroll down
1216      */
1217     @JsxFunction({FF, FF_ESR})
1218     public void scrollByLines(final int lines) {
1219         final HTMLElement body = document_.getBody();
1220         if (body != null) {
1221             body.setScrollTop(body.getScrollTop() + (19 * lines));
1222 
1223             fireScrollEvent(body);
1224         }
1225 
1226         fireScrollEvent(document_);
1227     }
1228 
1229     /**
1230      * Scrolls the window content down by the specified number of pages.
1231      * @param pages the number of pages to scroll down
1232      */
1233     @JsxFunction({FF, FF_ESR})
1234     public void scrollByPages(final int pages) {
1235         final HTMLElement body = document_.getBody();
1236         if (body != null) {
1237             body.setScrollTop(body.getScrollTop() + (getInnerHeight() * pages));
1238 
1239             fireScrollEvent(body);
1240         }
1241 
1242         fireScrollEvent(document_);
1243     }
1244 
1245     /**
1246      * Scrolls to the specified location on the page.
1247      * @param x the horizontal position to scroll to
1248      * @param y the vertical position to scroll to
1249      */
1250     @JsxFunction
1251     public void scrollTo(final Scriptable x, final Scriptable y) {
1252         final HTMLElement body = document_.getBody();
1253         if (body != null) {
1254             int xOff;
1255             int yOff;
1256             if (y != null) {
1257                 xOff = JavaScriptEngine.toInt32(x);
1258                 yOff = JavaScriptEngine.toInt32(y);
1259             }
1260             else {
1261                 if (!(x instanceof NativeObject)) {
1262                     throw JavaScriptEngine.typeError("eee");
1263                 }
1264 
1265                 xOff = body.getScrollLeft();
1266                 yOff = body.getScrollTop();
1267 
1268                 if (x.has("left", x)) {
1269                     xOff = JavaScriptEngine.toInt32(x.get("left", x));
1270                 }
1271                 if (x.has("top", x)) {
1272                     yOff = JavaScriptEngine.toInt32(x.get("top", x));
1273                 }
1274             }
1275             body.setScrollLeft(xOff);
1276             body.setScrollTop(yOff);
1277 
1278             fireScrollEvent(body);
1279         }
1280 
1281         fireScrollEvent(document_);
1282     }
1283 
1284     /**
1285      * Returns the {@code onload} property. Note that this is not necessarily a function if something else has been set.
1286      * @return the {@code onload} property
1287      */
1288     @JsxGetter
1289     public Function getOnload() {
1290         return getEventHandler(Event.TYPE_LOAD);
1291     }
1292 
1293     /**
1294      * Sets the value of the {@code onload} event handler.
1295      * @param onload the new handler
1296      */
1297     @JsxSetter
1298     public void setOnload(final Object onload) {
1299         setHandlerForJavaScript(Event.TYPE_LOAD, onload);
1300     }
1301 
1302     /**
1303      * Sets the value of the {@code onblur} event handler.
1304      * @param onblur the new handler
1305      */
1306     @JsxSetter
1307     public void setOnblur(final Object onblur) {
1308         setHandlerForJavaScript(Event.TYPE_BLUR, onblur);
1309     }
1310 
1311     /**
1312      * Returns the {@code onblur} property (not necessary a function if something else has been set).
1313      * @return the {@code onblur} property
1314      */
1315     @JsxGetter
1316     public Function getOnblur() {
1317         return getEventHandler(Event.TYPE_BLUR);
1318     }
1319 
1320     /**
1321      * Returns the {@code onclick} property (not necessary a function if something else has been set).
1322      * @return the {@code onclick} property
1323      */
1324     @JsxGetter
1325     public Function getOnclick() {
1326         return getEventHandler(MouseEvent.TYPE_CLICK);
1327     }
1328 
1329     /**
1330      * Sets the value of the {@code onclick} event handler.
1331      * @param onclick the new handler
1332      */
1333     @JsxSetter
1334     public void setOnclick(final Object onclick) {
1335         setHandlerForJavaScript(MouseEvent.TYPE_CLICK, onclick);
1336     }
1337 
1338     /**
1339      * Returns the {@code ondblclick} property (not necessary a function if something else has been set).
1340      * @return the {@code ondblclick} property
1341      */
1342     @JsxGetter
1343     public Function getOndblclick() {
1344         return getEventHandler(MouseEvent.TYPE_DBL_CLICK);
1345     }
1346 
1347     /**
1348      * Sets the value of the {@code ondblclick} event handler.
1349      * @param ondblclick the new handler
1350      */
1351     @JsxSetter
1352     public void setOndblclick(final Object ondblclick) {
1353         setHandlerForJavaScript(MouseEvent.TYPE_DBL_CLICK, ondblclick);
1354     }
1355 
1356     /**
1357      * Returns the {@code onhashchange} property (not necessary a function if something else has been set).
1358      * @return the {@code onhashchange} property
1359      */
1360     @JsxGetter
1361     public Function getOnhashchange() {
1362         return getEventHandler(Event.TYPE_HASH_CHANGE);
1363     }
1364 
1365     /**
1366      * Sets the value of the {@code onhashchange} event handler.
1367      * @param onhashchange the new handler
1368      */
1369     @JsxSetter
1370     public void setOnhashchange(final Object onhashchange) {
1371         setHandlerForJavaScript(Event.TYPE_HASH_CHANGE, onhashchange);
1372     }
1373 
1374     /**
1375      * Returns the value of the window's {@code name} property.
1376      * @return the value of the window's {@code name} property
1377      */
1378     @JsxGetter
1379     public String getName() {
1380         return getWebWindow().getName();
1381     }
1382 
1383      /**
1384       * Sets the value of the window's {@code name} property.
1385       * @param name the value of the window's {@code name} property
1386       */
1387     @JsxSetter
1388     public void setName(final String name) {
1389         getWebWindow().setName(name);
1390     }
1391 
1392     /**
1393      * Returns the value of the window's {@code onbeforeunload} property.
1394      * @return the value of the window's {@code onbeforeunload} property
1395      */
1396     @JsxGetter
1397     public Function getOnbeforeunload() {
1398         return getEventHandler(Event.TYPE_BEFORE_UNLOAD);
1399     }
1400 
1401     /**
1402      * Sets the value of the window's {@code onbeforeunload} property.
1403      * @param onbeforeunload the value of the window's {@code onbeforeunload} property
1404      */
1405     @JsxSetter
1406     public void setOnbeforeunload(final Object onbeforeunload) {
1407         setHandlerForJavaScript(Event.TYPE_BEFORE_UNLOAD, onbeforeunload);
1408     }
1409 
1410     /**
1411      * Returns the value of the window's {@code onerror} property.
1412      * @return the value of the window's {@code onerror} property
1413      */
1414     @JsxGetter
1415     public Function getOnerror() {
1416         return getEventHandler(Event.TYPE_ERROR);
1417     }
1418 
1419     /**
1420      * Sets the value of the window's {@code onerror} property.
1421      * @param onerror the value of the window's {@code onerror} property
1422      */
1423     @JsxSetter
1424     public void setOnerror(final Object onerror) {
1425         setHandlerForJavaScript(Event.TYPE_ERROR, onerror);
1426     }
1427 
1428     /**
1429      * Returns the value of the window's {@code onmessage} property.
1430      * @return the value of the window's {@code onmessage} property
1431      */
1432     @JsxGetter
1433     public Function getOnmessage() {
1434         return getEventHandler(Event.TYPE_MESSAGE);
1435     }
1436 
1437     /**
1438      * Sets the value of the window's {@code onmessage} property.
1439      * @param onmessage the value of the window's {@code onmessage} property
1440      */
1441     @JsxSetter
1442     public void setOnmessage(final Object onmessage) {
1443         setHandlerForJavaScript(Event.TYPE_MESSAGE, onmessage);
1444     }
1445 
1446     /**
1447      * Triggers the {@code onerror} handler, if one has been set.
1448      * @param e the error that needs to be reported
1449      */
1450     public void triggerOnError(final ScriptException e) {
1451         final Function f = getOnerror();
1452         if (f != null) {
1453             String msg = e.getMessage();
1454             final String url = e.getPage().getUrl().toExternalForm();
1455 
1456             final int line = e.getFailingLineNumber();
1457             final int column = e.getFailingColumnNumber();
1458 
1459             final TopLevel scope = getTopLevelScope(getParentScope());
1460 
1461             Object jsError = e.getMessage();
1462             if (e.getCause() instanceof JavaScriptException) {
1463                 msg = "uncaught exception: " + e.getCause().getMessage();
1464                 jsError = ((JavaScriptException) e.getCause()).getValue();
1465             }
1466             else if (e.getCause() instanceof EcmaError ecmaError) {
1467                 msg = "uncaught " + e.getCause().getMessage();
1468 
1469                 final Scriptable err = JavaScriptEngine.newObject(scope, "Error", JavaScriptEngine.EMPTY_ARGS);
1470                 ScriptableObject.putProperty(err, "message", ecmaError.getMessage());
1471                 ScriptableObject.putProperty(err, "fileName", ecmaError.sourceName());
1472                 ScriptableObject.putProperty(err, "lineNumber", Integer.valueOf(ecmaError.lineNumber()));
1473                 jsError = err;
1474             }
1475 
1476             final Object[] args = {msg, url, Integer.valueOf(line), Integer.valueOf(column), jsError};
1477             f.call(Context.getCurrentContext(), scope, this, args);
1478         }
1479     }
1480 
1481     private void setHandlerForJavaScript(final String eventName, final Object handler) {
1482         getEventListenersContainer().setEventHandler(eventName, handler);
1483     }
1484 
1485     /**
1486      * {@inheritDoc}
1487      */
1488     @Override
1489     protected Object getWithPreemption(final String name) {
1490         final DomNode domNode = getDomNodeOrNull();
1491         if (domNode == null) {
1492             return NOT_FOUND;
1493         }
1494 
1495         // May be attempting to retrieve a frame by name.
1496         final HtmlPage page = (HtmlPage) domNode.getPage();
1497         Object result = getFrameWindowByName(page, name);
1498 
1499         if (result == NOT_FOUND) {
1500             result = getElementsByName(page, name);
1501 
1502             if (result == NOT_FOUND) {
1503                 // May be attempting to retrieve element by ID (try map-backed operation again instead of XPath).
1504                 try {
1505                     final HtmlElement htmlElement = page.getHtmlElementById(name);
1506                     result = getScriptableFor(htmlElement);
1507                 }
1508                 catch (final ElementNotFoundException e) {
1509                     result = NOT_FOUND;
1510                 }
1511             }
1512         }
1513 
1514         if (result instanceof Window window) {
1515             final WebWindow webWindow = window.getWebWindow();
1516             result = getProxy(webWindow);
1517         }
1518 
1519         return result;
1520     }
1521 
1522     /**
1523      * {@inheritDoc}
1524      */
1525     @Override
1526     public Object get(final int index, final Scriptable start) {
1527         if (index < 0 || getWebWindow() == null) {
1528             return JavaScriptEngine.UNDEFINED;
1529         }
1530 
1531         final HTMLCollection frames = getFrames();
1532         if (frames == null || index >= frames.getLength()) {
1533             return JavaScriptEngine.UNDEFINED;
1534         }
1535         return frames.item(Integer.valueOf(index));
1536     }
1537 
1538     private static Object getFrameWindowByName(final HtmlPage page, final String name) {
1539         try {
1540             return page.getFrameByName(name).getScriptableObject();
1541         }
1542         catch (final ElementNotFoundException e) {
1543             return NOT_FOUND;
1544         }
1545     }
1546 
1547     private Object getElementsByName(final HtmlPage page, final String name) {
1548 
1549         // May be attempting to retrieve element(s) by name. IMPORTANT: We're using map-backed operations
1550         // like getHtmlElementsByName() and getHtmlElementById() as much as possible, so as to avoid XPath
1551         // overhead. We only use an XPath-based operation when we have to (where there is more than one
1552         // matching element). This optimization appears to improve performance in certain situations by ~15%
1553         // vs using XPath-based operations throughout.
1554         final List<DomElement> elements = page.getElementsByName(name);
1555 
1556         final Filter filter = new Filter(false);
1557 
1558         elements.removeIf(domElement -> !filter.matches(domElement));
1559 
1560         if (elements.isEmpty()) {
1561             return NOT_FOUND;
1562         }
1563 
1564         if (elements.size() == 1) {
1565             return getScriptableFor(elements.get(0));
1566         }
1567 
1568         // Null must be changed to '' for proper collection initialization.
1569         final String expElementName = "null".equals(name) ? "" : name;
1570 
1571         final HTMLCollection coll = new HTMLCollection(page, true);
1572         coll.setElementsSupplier(
1573                 (Supplier<List<DomNode>> & Serializable)
1574                 () -> {
1575                     final List<DomElement> expElements = page.getElementsByName(expElementName);
1576                     final List<DomNode> result = new ArrayList<>(expElements.size());
1577 
1578                     for (final DomElement domElement : expElements) {
1579                         if (filter.matches(domElement)) {
1580                             result.add(domElement);
1581                         }
1582                     }
1583                     return result;
1584                 });
1585 
1586         coll.setEffectOnCacheFunction(
1587                 (java.util.function.Function<HtmlAttributeChangeEvent, EffectOnCache> & Serializable)
1588                 event -> {
1589                     if ("name".equals(event.getName())) {
1590                         return EffectOnCache.RESET;
1591                     }
1592                     return EffectOnCache.NONE;
1593                 });
1594 
1595         return coll;
1596     }
1597 
1598     /**
1599      * Returns the proxy for the specified window.
1600      * @param w the window whose proxy is to be returned
1601      * @return the proxy for the specified window
1602      */
1603     public static WindowProxy getProxy(final WebWindow w) {
1604         return ((Window) w.getScriptableObject()).windowProxy_;
1605     }
1606 
1607     /**
1608      * Returns the text from the status line.
1609      * @return the status line text
1610      */
1611     @JsxGetter
1612     public String getStatus() {
1613         return status_;
1614     }
1615 
1616     /**
1617      * Sets the text from the status line.
1618      * @param message the status line text
1619      */
1620     @JsxSetter
1621     public void setStatus(final String message) {
1622         status_ = message;
1623 
1624         final StatusHandler statusHandler = webWindow_.getWebClient().getStatusHandler();
1625         if (statusHandler != null) {
1626             statusHandler.statusMessageChanged(webWindow_.getEnclosedPage(), message);
1627         }
1628     }
1629 
1630     /**
1631      * Returns the {@code innerWidth}.
1632      * @return the {@code innerWidth}
1633      * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref28.html">Mozilla doc</a>
1634      */
1635     @JsxGetter
1636     public int getInnerWidth() {
1637         return getWebWindow().getInnerWidth();
1638     }
1639 
1640     /**
1641      * Sets the {@code innerWidth}.
1642      * @param width the {@code innerWidth}
1643      */
1644     @JsxSetter
1645     public void setInnerWidth(final int width) {
1646         getWebWindow().setInnerWidth(width);
1647     }
1648 
1649     /**
1650      * Returns the {@code outerWidth}.
1651      * @return the {@code outerWidth}
1652      * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref79.html">Mozilla doc</a>
1653      */
1654     @JsxGetter
1655     public int getOuterWidth() {
1656         return getWebWindow().getOuterWidth();
1657     }
1658 
1659     /**
1660      * Sets the {@code outerWidth}.
1661      * @param width the {@code outerWidth}
1662      */
1663     @JsxSetter
1664     public void setOuterWidth(final int width) {
1665         getWebWindow().setOuterWidth(width);
1666     }
1667 
1668     /**
1669      * Returns the {@code innerHeight}.
1670      * @return the {@code innerHeight}
1671      * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref27.html">Mozilla doc</a>
1672      */
1673     @JsxGetter
1674     public int getInnerHeight() {
1675         return getWebWindow().getInnerHeight();
1676     }
1677 
1678     /**
1679      * Sets the {@code innerHeight}.
1680      * @param height the {@code innerHeight}
1681      */
1682     @JsxSetter
1683     public void setInnerHeight(final int height) {
1684         getWebWindow().setInnerHeight(height);
1685     }
1686 
1687     /**
1688      * Returns the {@code outerHeight}.
1689      * @return the {@code outerHeight}
1690      * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref78.html">Mozilla doc</a>
1691      */
1692     @JsxGetter
1693     public int getOuterHeight() {
1694         return getWebWindow().getOuterHeight();
1695     }
1696 
1697     /**
1698      * Sets the {@code outerHeight}.
1699      * @param height the {@code outerHeight}
1700      */
1701     @JsxSetter
1702     public void setOuterHeight(final int height) {
1703         getWebWindow().setOuterHeight(height);
1704     }
1705 
1706     /**
1707      * Prints the current page. The current implementation uses the {@link PrintHandler}
1708      * defined for the {@link WebClient} to process the window.
1709      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/print">MDN documentation</a>
1710      */
1711     @JsxFunction
1712     public void print() {
1713         final PrintHandler handler = getWebWindow().getWebClient().getPrintHandler();
1714         if (handler == null) {
1715             LOG.info("No PrintHandler installed - window.print() ignored");
1716             return;
1717         }
1718 
1719         final SgmlPage sgmlPage = getDocument().getPage();
1720         if (!(sgmlPage instanceof HtmlPage page)) {
1721             LOG.debug("Page is not an HtmlPage - window.print() ignored");
1722             return;
1723         }
1724 
1725         Event event = new Event(this, Event.TYPE_BEFOREPRINT);
1726         fireEvent(event);
1727 
1728         page.setPrinting(true);
1729         try {
1730             handler.handlePrint(page);
1731         }
1732         finally {
1733             page.setPrinting(false);
1734         }
1735         event = new Event(this, Event.TYPE_AFTERPRINT);
1736         fireEvent(event);
1737     }
1738 
1739     /**
1740      * Does nothing special anymore.
1741      * @param type the type of events to capture
1742      * @see HTMLDocument#captureEvents(String)
1743      */
1744     @JsxFunction
1745     public void captureEvents(final String type) {
1746         // Empty.
1747     }
1748 
1749     /**
1750      * Does nothing special anymore.
1751      * @param type the type of events to capture
1752      * @see HTMLDocument#releaseEvents(String)
1753      */
1754     @JsxFunction
1755     public void releaseEvents(final String type) {
1756         // Empty.
1757     }
1758 
1759     /**
1760      * Returns computed style of the element. Computed style represents the final computed values
1761      * of all CSS properties for the element. This method's return value is of the same type as
1762      * that of <code>element.style</code>, but the value returned by this method is read-only.
1763      *
1764      * @param element the element
1765      * @param pseudoElement a string specifying the pseudo-element to match (may be {@code null});
1766      *        e.g. ':before'
1767      * @return the computed style
1768      */
1769     @JsxFunction
1770     public ComputedCSSStyleDeclaration getComputedStyle(final Object element, final String pseudoElement) {
1771         if (!(element instanceof Element e)) {
1772             throw JavaScriptEngine.typeError("parameter 1 is not of type 'Element'");
1773         }
1774 
1775         final ComputedCssStyleDeclaration style = getWebWindow().getComputedStyle(e.getDomNodeOrDie(), pseudoElement);
1776         return new ComputedCSSStyleDeclaration(e, style);
1777     }
1778 
1779     /**
1780      * Returns the current selection.
1781      * @return the current selection
1782      */
1783     @JsxFunction
1784     public Selection getSelection() {
1785         final WebWindow webWindow = getWebWindow();
1786         // return null if the window is in a frame that is not displayed
1787         if (webWindow instanceof FrameWindow frameWindow) {
1788             if (getBrowserVersion().hasFeature(JS_WINDOW_SELECTION_NULL_IF_INVISIBLE)
1789                     && !frameWindow.getFrameElement().isDisplayed()) {
1790                 return null;
1791             }
1792         }
1793         return getSelectionImpl();
1794     }
1795 
1796     /**
1797      * Returns the current selection.
1798      * @return the current selection
1799      */
1800     public Selection getSelectionImpl() {
1801         if (selection_ == null) {
1802             selection_ = new Selection();
1803             selection_.setParentScope(getParentScope());
1804             selection_.setPrototype(getPrototype(selection_.getClass()));
1805         }
1806         return selection_;
1807     }
1808 
1809     /**
1810      * Gets the {@code controllers}. The result doesn't currently matter but it is important to return an
1811      * object as some JavaScript libraries check it.
1812      * @see <a href="https://developer.mozilla.org/En/DOM/Window.controllers">Mozilla documentation</a>
1813      * @return some object
1814      */
1815     @JsxGetter({FF, FF_ESR})
1816     public Object getControllers() {
1817         return controllers_;
1818     }
1819 
1820     /**
1821      * Sets the {@code controllers}.
1822      * @param value the new value
1823      */
1824     @JsxSetter({FF, FF_ESR})
1825     public void setControllers(final Object value) {
1826         controllers_ = value;
1827     }
1828 
1829     /**
1830      * Returns the value of {@code mozInnerScreenX} property.
1831      * @return the value of {@code mozInnerScreenX} property
1832      */
1833     @JsxGetter({FF, FF_ESR})
1834     public int getMozInnerScreenX() {
1835         return 12;
1836     }
1837 
1838     /**
1839      * Returns the value of {@code mozInnerScreenY} property.
1840      * @return the value of {@code mozInnerScreenY} property
1841      */
1842     @JsxGetter({FF, FF_ESR})
1843     public int getMozInnerScreenY() {
1844         return 90;
1845     }
1846 
1847     private static final class Filter {
1848         private final boolean includeFormFields_;
1849 
1850         Filter(final boolean includeFormFields) {
1851             includeFormFields_ = includeFormFields;
1852         }
1853 
1854         boolean matches(final Object object) {
1855             if (object instanceof HtmlEmbed
1856                 || object instanceof HtmlForm
1857                 || object instanceof HtmlImage
1858                 || object instanceof HtmlObject) {
1859                 return true;
1860             }
1861 
1862             return includeFormFields_
1863                     && (object instanceof HtmlAnchor
1864                         || object instanceof HtmlButton
1865                         || object instanceof HtmlInput
1866                         || object instanceof HtmlMap
1867                         || object instanceof HtmlSelect
1868                         || object instanceof HtmlTextArea);
1869         }
1870     }
1871 
1872     /**
1873      * Should implement the stop() function on the window object.
1874      * (currently empty implementation)
1875      * @see <a href="https://developer.mozilla.org/en/DOM/window.stop">window.stop</a>
1876      */
1877     @JsxFunction
1878     public void stop() {
1879         //empty
1880     }
1881 
1882     /**
1883      * Returns the value of {@code pageXOffset} property.
1884      * @return the value of {@code pageXOffset} property
1885      */
1886     @JsxGetter
1887     public int getPageXOffset() {
1888         return 0;
1889     }
1890 
1891     /**
1892      * Returns the value of {@code pageYOffset} property.
1893      * @return the value of {@code pageYOffset} property
1894      */
1895     @JsxGetter
1896     public int getPageYOffset() {
1897         return 0;
1898     }
1899 
1900     /**
1901      * Returns the value of {@code scrollX} property.
1902      * @return the value of {@code scrollX} property
1903      */
1904     @JsxGetter
1905     public int getScrollX() {
1906         return 0;
1907     }
1908 
1909     /**
1910      * Returns the value of {@code scrollY} property.
1911      * @return the value of {@code scrollY} property
1912      */
1913     @JsxGetter
1914     public int getScrollY() {
1915         return 0;
1916     }
1917 
1918     /**
1919      * Returns the {@code netscape} property.
1920      *
1921      * @return the value of {@code netscape} property
1922      */
1923     @JsxGetter({FF, FF_ESR})
1924     public Netscape getNetscape() {
1925         return new Netscape(getParentScope());
1926     }
1927 
1928     /**
1929      * {@inheritDoc}
1930      * Used to allow re-declaration of constants (eg: "var undefined;").
1931      */
1932     @Override
1933     public boolean isConst(final Context cx, final String name) {
1934         if ("undefined".equals(name) || "Infinity".equals(name) || "NaN".equals(name)) {
1935             return false;
1936         }
1937 
1938         return super.isConst(cx, name);
1939     }
1940 
1941     /**
1942      * {@inheritDoc}
1943      */
1944     @Override
1945     public boolean dispatchEvent(final Event event) {
1946         event.setTarget(this);
1947         final ScriptResult result = fireEvent(event);
1948         return !event.isAborted(result);
1949     }
1950 
1951     /**
1952      * Getter for the {@code onchange} event handler.
1953      * @return the handler
1954      */
1955     @JsxGetter
1956     public Function getOnchange() {
1957         return getEventHandler(Event.TYPE_CHANGE);
1958     }
1959 
1960     /**
1961      * Setter for the {@code onchange} event handler.
1962      * @param onchange the handler
1963      */
1964     @JsxSetter
1965     public void setOnchange(final Object onchange) {
1966         setHandlerForJavaScript(Event.TYPE_CHANGE, onchange);
1967     }
1968 
1969     /**
1970      * Getter for the {@code onsubmit} event handler.
1971      * @return the handler
1972      */
1973     @JsxGetter
1974     public Function getOnsubmit() {
1975         return getEventHandler(Event.TYPE_SUBMIT);
1976     }
1977 
1978     /**
1979      * Setter for the {@code onsubmit} event handler.
1980      * @param onsubmit the handler
1981      */
1982     @JsxSetter
1983     public void setOnsubmit(final Object onsubmit) {
1984         setHandlerForJavaScript(Event.TYPE_SUBMIT, onsubmit);
1985     }
1986 
1987     /**
1988      * Posts a message.
1989      * @param context the current context
1990      * @param scope the scope
1991      * @param thisObj this object
1992      * @param args the script(s) to import
1993      * @param funObj the JS function called
1994      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage">MDN documentation</a>
1995      */
1996     @JsxFunction
1997     public static void postMessage(final Context context, final VarScope scope,
1998             final Scriptable thisObj, final Object[] args, final Function funObj) {
1999 
2000         // support the structured clone algorithm
2001         if (args.length < 1) {
2002             throw JavaScriptEngine.typeError("message not provided");
2003         }
2004         final Object message = args[0];
2005 
2006         String targetOrigin = "*";
2007         Object transfer = JavaScriptEngine.UNDEFINED;
2008 
2009         if (args.length > 1) {
2010             if (JavaScriptEngine.isArray(args[1])) {
2011                 transfer = args[1];
2012             }
2013             else {
2014                 targetOrigin = JavaScriptEngine.toString(args[1]);
2015             }
2016         }
2017 
2018         if (args.length > 2) {
2019             if (JavaScriptEngine.isArray(args[2])) {
2020                 transfer = args[2];
2021             }
2022         }
2023 
2024         final TopLevel topLevel = ScriptableObject.getTopLevelScope(scope);
2025         final Window sender = (Window) topLevel.getGlobalThis();
2026         final Window receiver = (Window) thisObj;
2027         final URL receiverURL = receiver.getWebWindow().getEnclosedPage().getUrl();
2028 
2029         final WebWindow webWindow = sender.getWebWindow();
2030         final Page page = webWindow.getEnclosedPage();
2031         final URL senderURL = page.getUrl();
2032 
2033         if (!StringUtils.equalsChar('*', targetOrigin)) {
2034             final URL targetURL;
2035             if (StringUtils.equalsChar('/', targetOrigin)) {
2036                 targetURL = senderURL;
2037             }
2038             else {
2039                 try {
2040                     targetURL = new URL(targetOrigin);
2041                 }
2042                 catch (final Exception e) {
2043                     throw JavaScriptEngine.asJavaScriptException(
2044                             sender,
2045                             "Failed to execute 'postMessage' on 'Window': Invalid target origin '"
2046                                     + targetOrigin + "' was specified (reason: " + e.getMessage() + ".",
2047                             DOMException.SYNTAX_ERR);
2048                 }
2049             }
2050 
2051             if (getPort(targetURL) != getPort(receiverURL)) {
2052                 return;
2053             }
2054             if (!targetURL.getHost().equals(receiverURL.getHost())) {
2055                 return;
2056             }
2057             if (!targetURL.getProtocol().equals(receiverURL.getProtocol())) {
2058                 return;
2059             }
2060         }
2061 
2062         final String origin;
2063         try {
2064             final URL originUrl = UrlUtils.getUrlWithoutPathRefQuery(senderURL);
2065             origin = UrlUtils.removeRedundantPort(originUrl).toExternalForm();
2066         }
2067         catch (final MalformedURLException e) {
2068             throw JavaScriptEngine.throwAsScriptRuntimeEx(e);
2069         }
2070 
2071         final MessageEvent event = new MessageEvent();
2072         event.initMessageEvent(Event.TYPE_MESSAGE, false, false, message, origin, "", sender, transfer);
2073         event.setParentScope(scope);
2074         event.setPrototype(receiver.getPrototype(event.getClass()));
2075 
2076         final AbstractJavaScriptEngine<?> jsEngine = webWindow.getWebClient().getJavaScriptEngine();
2077         final PostponedAction action = new PostponedAction(page, "Window.postMessage") {
2078             @Override
2079             public void execute() {
2080                 final HtmlUnitContextFactory cf = jsEngine.getContextFactory();
2081                 cf.call(cx -> receiver.dispatchEvent(event));
2082             }
2083         };
2084         jsEngine.addPostponedAction(action);
2085     }
2086 
2087     /**
2088      * Returns the port of the specified URL.
2089      * @param url the URL
2090      * @return the port
2091      */
2092     public static int getPort(final URL url) {
2093         int port = url.getPort();
2094         if (port == -1) {
2095             if ("http".equals(url.getProtocol())) {
2096                 port = 80;
2097             }
2098             else {
2099                 port = 443;
2100             }
2101         }
2102         return port;
2103     }
2104 
2105     /**
2106      * The performance attribute is defined as replacable
2107      * (https://w3c.github.io/hr-time/#the-performance-attribute) but not implemented
2108      * as that.
2109      * @return the value of the {@code performance} property
2110      */
2111     @JsxGetter
2112     public Scriptable getPerformance() {
2113         if (performance_ == null) {
2114             final Performance performance = new Performance();
2115             performance.setParentScope(getParentScope());
2116             performance.setPrototype(getPrototype(performance.getClass()));
2117             performance_ = performance;
2118         }
2119         return performance_;
2120     }
2121 
2122     /**
2123      * The performance attribute is defined as replacable
2124      * (https://w3c.github.io/hr-time/#the-performance-attribute) but not implemented
2125      * as that.
2126      * <p>
2127      * Sets the {@code performance} property.
2128      * </p>
2129      * @param performance the value to overwrite the defined property value
2130      */
2131     @JsxSetter
2132     public void setPerformance(final Scriptable performance) {
2133         performance_ = performance;
2134     }
2135 
2136     /**
2137      * Returns the {@code devicePixelRatio} property.
2138      * @return the {@code devicePixelRatio} property
2139      */
2140     @JsxGetter
2141     public int getDevicePixelRatio() {
2142         return 1;
2143     }
2144 
2145     /**
2146      * Returns the {@code styleMedia} property.
2147      * @return the {@code styleMedia} property
2148      */
2149     @JsxGetter({CHROME, EDGE})
2150     public StyleMedia getStyleMedia() {
2151         final StyleMedia styleMedia = new StyleMedia();
2152         styleMedia.setParentScope(getParentScope());
2153         styleMedia.setPrototype(getPrototype(styleMedia.getClass()));
2154         return styleMedia;
2155     }
2156 
2157     /**
2158      * Returns a new MediaQueryList object representing the parsed results of the specified media query string.
2159      *
2160      * @param mediaQueryString the media query
2161      * @return a new MediaQueryList object
2162      */
2163     @JsxFunction
2164     public MediaQueryList matchMedia(final String mediaQueryString) {
2165         final MediaQueryList mediaQueryList = new MediaQueryList(mediaQueryString);
2166         mediaQueryList.setParentScope(getParentScope());
2167         mediaQueryList.setPrototype(getPrototype(mediaQueryList.getClass()));
2168         return mediaQueryList;
2169     }
2170 
2171     /**
2172      * Stub only at the moment.
2173      * @param search the text string for which to search
2174      * @param caseSensitive if true, specifies a case-sensitive search
2175      * @param backwards if true, specifies a backward search
2176      * @param wrapAround if true, specifies a wrap around search
2177      * @param wholeWord if true, specifies a whole word search
2178      * @param searchInFrames if true, specifies a search in frames
2179      * @param showDialog if true, specifies a show Dialog.
2180      * @return false
2181      */
2182     @JsxFunction
2183     public boolean find(final String search, final boolean caseSensitive,
2184             final boolean backwards, final boolean wrapAround,
2185             final boolean wholeWord, final boolean searchInFrames, final boolean showDialog) {
2186         return false;
2187     }
2188 
2189     /**
2190      * Returns the {@code speechSynthesis} property.
2191      * @return the {@code speechSynthesis} property
2192      */
2193     @JsxGetter({CHROME, EDGE})
2194     public SpeechSynthesis getSpeechSynthesis() {
2195         final SpeechSynthesis speechSynthesis = new SpeechSynthesis();
2196         speechSynthesis.setParentScope(getParentScope());
2197         speechSynthesis.setPrototype(getPrototype(speechSynthesis.getClass()));
2198         return speechSynthesis;
2199     }
2200 
2201     /**
2202      * Returns the {@code offscreenBuffering} property.
2203      * @return the {@code offscreenBuffering} property
2204      */
2205     @JsxGetter({CHROME, EDGE})
2206     public boolean isOffscreenBuffering() {
2207         return true;
2208     }
2209 
2210     /**
2211      * Returns the {@code crypto} property.
2212      * @return the {@code crypto} property
2213      */
2214     @JsxGetter
2215     public Crypto getCrypto() {
2216         if (crypto_ == null) {
2217             crypto_ = new Crypto(this);
2218         }
2219         return crypto_;
2220     }
2221 
2222     /**
2223      * {@inheritDoc}
2224      */
2225     @Override
2226     public void close() {
2227         // nothing to do
2228     }
2229 
2230     /**
2231      * Returns the {@code onfocus} event handler.
2232      * @return the {@code onfocus} event handler
2233      */
2234     @JsxGetter
2235     public Function getOnfocus() {
2236         return getEventHandler(Event.TYPE_FOCUS);
2237     }
2238 
2239     /**
2240      * Sets the {@code onfocus} event handler.
2241      * @param onfocus the {@code onfocus} event handler
2242      */
2243     @JsxSetter
2244     public void setOnfocus(final Object onfocus) {
2245         setHandlerForJavaScript(Event.TYPE_FOCUS, onfocus);
2246     }
2247 
2248     /**
2249      * Returns the {@code ondragend} event handler.
2250      * @return the {@code ondragend} event handler
2251      */
2252     @JsxGetter
2253     public Function getOndragend() {
2254         return getEventHandler(Event.TYPE_DRAGEND);
2255     }
2256 
2257     /**
2258      * Sets the {@code ondragend} event handler.
2259      * @param ondragend the {@code ondragend} event handler
2260      */
2261     @JsxSetter
2262     public void setOndragend(final Object ondragend) {
2263         setHandlerForJavaScript(Event.TYPE_DRAGEND, ondragend);
2264     }
2265 
2266     /**
2267      * Returns the {@code oninvalid} event handler.
2268      * @return the {@code oninvalid} event handler
2269      */
2270     @JsxGetter
2271     public Function getOninvalid() {
2272         return getEventHandler(Event.TYPE_INVALID);
2273     }
2274 
2275     /**
2276      * Sets the {@code oninvalid} event handler.
2277      * @param oninvalid the {@code oninvalid} event handler
2278      */
2279     @JsxSetter
2280     public void setOninvalid(final Object oninvalid) {
2281         setHandlerForJavaScript(Event.TYPE_INVALID, oninvalid);
2282     }
2283 
2284     /**
2285      * Returns the {@code onpointerout} event handler.
2286      * @return the {@code onpointerout} event handler
2287      */
2288     @JsxGetter({CHROME, EDGE})
2289     public Function getOnpointerout() {
2290         return getEventHandler(Event.TYPE_POINTEROUT);
2291     }
2292 
2293     /**
2294      * Sets the {@code onpointerout} event handler.
2295      * @param onpointerout the {@code onpointerout} event handler
2296      */
2297     @JsxSetter({CHROME, EDGE})
2298     public void setOnpointerout(final Object onpointerout) {
2299         setHandlerForJavaScript(Event.TYPE_POINTEROUT, onpointerout);
2300     }
2301 
2302     /**
2303      * Returns the {@code onratechange} event handler.
2304      * @return the {@code onratechange} event handler
2305      */
2306     @JsxGetter
2307     public Function getOnratechange() {
2308         return getEventHandler(Event.TYPE_RATECHANGE);
2309     }
2310 
2311     /**
2312      * Sets the {@code onratechange} event handler.
2313      * @param onratechange the {@code onratechange} event handler
2314      */
2315     @JsxSetter
2316     public void setOnratechange(final Object onratechange) {
2317         setHandlerForJavaScript(Event.TYPE_RATECHANGE, onratechange);
2318     }
2319 
2320     /**
2321      * Returns the {@code onanimationiteration} event handler.
2322      * @return the {@code onanimationiteration} event handler
2323      */
2324     @JsxGetter
2325     public Function getOnanimationiteration() {
2326         return getEventHandler(Event.TYPE_ANIMATIONITERATION);
2327     }
2328 
2329     /**
2330      * Sets the {@code onanimationiteration} event handler.
2331      * @param onanimationiteration the {@code onanimationiteration} event handler
2332      */
2333     @JsxSetter
2334     public void setOnanimationiteration(final Object onanimationiteration) {
2335         setHandlerForJavaScript(Event.TYPE_ANIMATIONITERATION, onanimationiteration);
2336     }
2337 
2338     /**
2339      * Returns the {@code oncanplaythrough} event handler.
2340      * @return the {@code oncanplaythrough} event handler
2341      */
2342     @JsxGetter
2343     public Function getOncanplaythrough() {
2344         return getEventHandler(Event.TYPE_CANPLAYTHROUGH);
2345     }
2346 
2347     /**
2348      * Sets the {@code oncanplaythrough} event handler.
2349      * @param oncanplaythrough the {@code oncanplaythrough} event handler
2350      */
2351     @JsxSetter
2352     public void setOncanplaythrough(final Object oncanplaythrough) {
2353         setHandlerForJavaScript(Event.TYPE_CANPLAYTHROUGH, oncanplaythrough);
2354     }
2355 
2356     /**
2357      * Returns the {@code oncancel} event handler.
2358      * @return the {@code oncancel} event handler
2359      */
2360     @JsxGetter({CHROME, EDGE})
2361     public Function getOncancel() {
2362         return getEventHandler(Event.TYPE_CANCEL);
2363     }
2364 
2365     /**
2366      * Sets the {@code oncancel} event handler.
2367      * @param oncancel the {@code oncancel} event handler
2368      */
2369     @JsxSetter({CHROME, EDGE})
2370     public void setOncancel(final Object oncancel) {
2371         setHandlerForJavaScript(Event.TYPE_CANCEL, oncancel);
2372     }
2373 
2374     /**
2375      * Returns the {@code onpointerenter} event handler.
2376      * @return the {@code onpointerenter} event handler
2377      */
2378     @JsxGetter({CHROME, EDGE})
2379     public Function getOnpointerenter() {
2380         return getEventHandler(Event.TYPE_POINTERENTER);
2381     }
2382 
2383     /**
2384      * Sets the {@code onpointerenter} event handler.
2385      * @param onpointerenter the {@code onpointerenter} event handler
2386      */
2387     @JsxSetter({CHROME, EDGE})
2388     public void setOnpointerenter(final Object onpointerenter) {
2389         setHandlerForJavaScript(Event.TYPE_POINTERENTER, onpointerenter);
2390     }
2391 
2392     /**
2393      * Returns the {@code onselect} event handler.
2394      * @return the {@code onselect} event handler
2395      */
2396     @JsxGetter
2397     public Function getOnselect() {
2398         return getEventHandler(Event.TYPE_SELECT);
2399     }
2400 
2401     /**
2402      * Sets the {@code onselect} event handler.
2403      * @param onselect the {@code onselect} event handler
2404      */
2405     @JsxSetter
2406     public void setOnselect(final Object onselect) {
2407         setHandlerForJavaScript(Event.TYPE_SELECT, onselect);
2408     }
2409 
2410     /**
2411      * Returns the {@code onauxclick} event handler.
2412      * @return the {@code onauxclick} event handler
2413      */
2414     @JsxGetter({CHROME, EDGE})
2415     public Function getOnauxclick() {
2416         return getEventHandler(Event.TYPE_AUXCLICK);
2417     }
2418 
2419     /**
2420      * Sets the {@code onauxclick} event handler.
2421      * @param onauxclick the {@code onauxclick} event handler
2422      */
2423     @JsxSetter({CHROME, EDGE})
2424     public void setOnauxclick(final Object onauxclick) {
2425         setHandlerForJavaScript(Event.TYPE_AUXCLICK, onauxclick);
2426     }
2427 
2428     /**
2429      * Returns the {@code onscroll} event handler.
2430      * @return the {@code onscroll} event handler
2431      */
2432     @JsxGetter
2433     public Function getOnscroll() {
2434         return getEventHandler(Event.TYPE_SCROLL);
2435     }
2436 
2437     /**
2438      * Sets the {@code onscroll} event handler.
2439      * @param onscroll the {@code onscroll} event handler
2440      */
2441     @JsxSetter
2442     public void setOnscroll(final Object onscroll) {
2443         setHandlerForJavaScript(Event.TYPE_SCROLL, onscroll);
2444     }
2445 
2446     /**
2447      * Returns the {@code onkeydown} event handler.
2448      * @return the {@code onkeydown} event handler
2449      */
2450     @JsxGetter
2451     public Function getOnkeydown() {
2452         return getEventHandler(Event.TYPE_KEY_DOWN);
2453     }
2454 
2455     /**
2456      * Sets the {@code onkeydown} event handler.
2457      * @param onkeydown the {@code onkeydown} event handler
2458      */
2459     @JsxSetter
2460     public void setOnkeydown(final Object onkeydown) {
2461         setHandlerForJavaScript(Event.TYPE_KEY_DOWN, onkeydown);
2462     }
2463 
2464     /**
2465      * Returns the {@code onwebkitanimationstart} event handler.
2466      * @return the {@code onwebkitanimationstart} event handler
2467      */
2468     @JsxGetter({CHROME, EDGE})
2469     public Function getOnwebkitanimationstart() {
2470         return getEventHandler(Event.TYPE_WEBANIMATIONSTART);
2471     }
2472 
2473     /**
2474      * Sets the {@code onwebkitanimationstart} event handler.
2475      * @param onwebkitanimationstart the {@code onwebkitanimationstart} event handler
2476      */
2477     @JsxSetter({CHROME, EDGE})
2478     public void setOnwebkitanimationstart(final Object onwebkitanimationstart) {
2479         setHandlerForJavaScript(Event.TYPE_WEBANIMATIONSTART, onwebkitanimationstart);
2480     }
2481 
2482     /**
2483      * Returns the {@code onkeyup} event handler.
2484      * @return the {@code onkeyup} event handler
2485      */
2486     @JsxGetter
2487     public Function getOnkeyup() {
2488         return getEventHandler(Event.TYPE_KEY_UP);
2489     }
2490 
2491     /**
2492      * Sets the {@code onkeyup} event handler.
2493      * @param onkeyup the {@code onkeyup} event handler
2494      */
2495     @JsxSetter
2496     public void setOnkeyup(final Object onkeyup) {
2497         setHandlerForJavaScript(Event.TYPE_KEY_UP, onkeyup);
2498     }
2499 
2500     /**
2501      * Returns the {@code onreset} event handler.
2502      * @return the {@code onreset} event handler
2503      */
2504     @JsxGetter
2505     public Function getOnreset() {
2506         return getEventHandler(Event.TYPE_RESET);
2507     }
2508 
2509     /**
2510      * Sets the {@code onreset} event handler.
2511      * @param onreset the {@code onreset} event handler
2512      */
2513     @JsxSetter
2514     public void setOnreset(final Object onreset) {
2515         setHandlerForJavaScript(Event.TYPE_RESET, onreset);
2516     }
2517 
2518     /**
2519      * Returns the {@code onkeypress} event handler.
2520      * @return the {@code onkeypress} event handler
2521      */
2522     @JsxGetter
2523     public Function getOnkeypress() {
2524         return getEventHandler(Event.TYPE_KEY_PRESS);
2525     }
2526 
2527     /**
2528      * Sets the {@code onkeypress} event handler.
2529      * @param onkeypress the {@code onkeypress} event handler
2530      */
2531     @JsxSetter
2532     public void setOnkeypress(final Object onkeypress) {
2533         setHandlerForJavaScript(Event.TYPE_KEY_PRESS, onkeypress);
2534     }
2535 
2536     /**
2537      * Returns the {@code ondrag} event handler.
2538      * @return the {@code ondrag} event handler
2539      */
2540     @JsxGetter
2541     public Function getOndrag() {
2542         return getEventHandler(Event.TYPE_DRAG);
2543     }
2544 
2545     /**
2546      * Sets the {@code ondrag} event handler.
2547      * @param ondrag the {@code ondrag} event handler
2548      */
2549     @JsxSetter
2550     public void setOndrag(final Object ondrag) {
2551         setHandlerForJavaScript(Event.TYPE_DRAG, ondrag);
2552     }
2553 
2554     /**
2555      * Returns the {@code onseeked} event handler.
2556      * @return the {@code onseeked} event handler
2557      */
2558     @JsxGetter
2559     public Function getOnseeked() {
2560         return getEventHandler(Event.TYPE_SEEKED);
2561     }
2562 
2563     /**
2564      * Sets the {@code onseeked} event handler.
2565      * @param onseeked the {@code onseeked} event handler
2566      */
2567     @JsxSetter
2568     public void setOnseeked(final Object onseeked) {
2569         setHandlerForJavaScript(Event.TYPE_SEEKED, onseeked);
2570     }
2571 
2572     /**
2573      * Returns the {@code onoffline} event handler.
2574      * @return the {@code onoffline} event handler
2575      */
2576     @JsxGetter
2577     public Function getOnoffline() {
2578         return getEventHandler(Event.TYPE_OFFLINE);
2579     }
2580 
2581     /**
2582      * Sets the {@code onoffline} event handler.
2583      * @param onoffline the {@code onoffline} event handler
2584      */
2585     @JsxSetter
2586     public void setOnoffline(final Object onoffline) {
2587         setHandlerForJavaScript(Event.TYPE_OFFLINE, onoffline);
2588     }
2589 
2590     /**
2591      * Returns the {@code ondeviceorientation} event handler.
2592      * @return the {@code ondeviceorientation} event handler
2593      */
2594     @JsxGetter
2595     public Function getOndeviceorientation() {
2596         return getEventHandler(Event.TYPE_DEVICEORIENTATION);
2597     }
2598 
2599     /**
2600      * Sets the {@code ondeviceorientation} event handler.
2601      * @param ondeviceorientation the {@code ondeviceorientation} event handler
2602      */
2603     @JsxSetter
2604     public void setOndeviceorientation(final Object ondeviceorientation) {
2605         setHandlerForJavaScript(Event.TYPE_DEVICEORIENTATION, ondeviceorientation);
2606     }
2607 
2608     /**
2609      * Returns the {@code ontoggle} event handler.
2610      * @return the {@code ontoggle} event handler
2611      */
2612     @JsxGetter({CHROME, EDGE})
2613     public Function getOntoggle() {
2614         return getEventHandler(Event.TYPE_TOGGLE);
2615     }
2616 
2617     /**
2618      * Sets the {@code ontoggle} event handler.
2619      * @param ontoggle the {@code ontoggle} event handler
2620      */
2621     @JsxSetter({CHROME, EDGE})
2622     public void setOntoggle(final Object ontoggle) {
2623         setHandlerForJavaScript(Event.TYPE_TOGGLE, ontoggle);
2624     }
2625 
2626     /**
2627      * Returns the {@code onplay} event handler.
2628      * @return the {@code onplay} event handler
2629      */
2630     @JsxGetter
2631     public Function getOnplay() {
2632         return getEventHandler(Event.TYPE_PLAY);
2633     }
2634 
2635     /**
2636      * Sets the {@code onplay} event handler.
2637      * @param onplay the {@code onplay} event handler
2638      */
2639     @JsxSetter
2640     public void setOnplay(final Object onplay) {
2641         setHandlerForJavaScript(Event.TYPE_PLAY, onplay);
2642     }
2643 
2644     /**
2645      * Returns the {@code oncontextmenu} event handler.
2646      * @return the {@code oncontextmenu} event handler
2647      */
2648     @JsxGetter
2649     public Function getOncontextmenu() {
2650         return getEventHandler(MouseEvent.TYPE_CONTEXT_MENU);
2651     }
2652 
2653     /**
2654      * Sets the {@code oncontextmenu} event handler.
2655      * @param oncontextmenu the {@code oncontextmenu} event handler
2656      */
2657     @JsxSetter
2658     public void setOncontextmenu(final Object oncontextmenu) {
2659         setHandlerForJavaScript(MouseEvent.TYPE_CONTEXT_MENU, oncontextmenu);
2660     }
2661 
2662     /**
2663      * Returns the {@code onmousemove} event handler.
2664      * @return the {@code onmousemove} event handler
2665      */
2666     @JsxGetter
2667     public Function getOnmousemove() {
2668         return getEventHandler(MouseEvent.TYPE_MOUSE_MOVE);
2669     }
2670 
2671     /**
2672      * Sets the {@code onmousemove} event handler.
2673      * @param onmousemove the {@code onmousemove} event handler
2674      */
2675     @JsxSetter
2676     public void setOnmousemove(final Object onmousemove) {
2677         setHandlerForJavaScript(MouseEvent.TYPE_MOUSE_MOVE, onmousemove);
2678     }
2679 
2680     /**
2681      * Returns the {@code onpointermove} event handler.
2682      * @return the {@code onpointermove} event handler
2683      */
2684     @JsxGetter({CHROME, EDGE})
2685     public Function getOnpointermove() {
2686         return getEventHandler(Event.TYPE_POINTERMOVE);
2687     }
2688 
2689     /**
2690      * Sets the {@code onpointermove} event handler.
2691      * @param onpointermove the {@code onpointermove} event handler
2692      */
2693     @JsxSetter({CHROME, EDGE})
2694     public void setOnpointermove(final Object onpointermove) {
2695         setHandlerForJavaScript(Event.TYPE_POINTERMOVE, onpointermove);
2696     }
2697 
2698     /**
2699      * Returns the {@code onmouseover} event handler.
2700      * @return the {@code onmouseover} event handler
2701      */
2702     @JsxGetter
2703     public Function getOnmouseover() {
2704         return getEventHandler(MouseEvent.TYPE_MOUSE_OVER);
2705     }
2706 
2707     /**
2708      * Sets the {@code onmouseover} event handler.
2709      * @param onmouseover the {@code onmouseover} event handler
2710      */
2711     @JsxSetter
2712     public void setOnmouseover(final Object onmouseover) {
2713         setHandlerForJavaScript(MouseEvent.TYPE_MOUSE_OVER, onmouseover);
2714     }
2715 
2716     /**
2717      * Returns the {@code onlostpointercapture} event handler.
2718      * @return the {@code onlostpointercapture} event handler
2719      */
2720     @JsxGetter({CHROME, EDGE})
2721     public Function getOnlostpointercapture() {
2722         return getEventHandler(Event.TYPE_LOSTPOINTERCAPTURE);
2723     }
2724 
2725     /**
2726      * Sets the {@code onlostpointercapture} event handler.
2727      * @param onlostpointercapture the {@code onlostpointercapture} event handler
2728      */
2729     @JsxSetter({CHROME, EDGE})
2730     public void setOnlostpointercapture(final Object onlostpointercapture) {
2731         setHandlerForJavaScript(Event.TYPE_LOSTPOINTERCAPTURE, onlostpointercapture);
2732     }
2733 
2734     /**
2735      * Returns the {@code onpointerover} event handler.
2736      * @return the {@code onpointerover} event handler
2737      */
2738     @JsxGetter({CHROME, EDGE})
2739     public Function getOnpointerover() {
2740         return getEventHandler(Event.TYPE_POINTEROVER);
2741     }
2742 
2743     /**
2744      * Sets the {@code onpointerover} event handler.
2745      * @param onpointerover the {@code onpointerover} event handler
2746      */
2747     @JsxSetter({CHROME, EDGE})
2748     public void setOnpointerover(final Object onpointerover) {
2749         setHandlerForJavaScript(Event.TYPE_POINTEROVER, onpointerover);
2750     }
2751 
2752     /**
2753      * Returns the {@code onclose} event handler.
2754      * @return the {@code onclose} event handler
2755      */
2756     @JsxGetter({CHROME, EDGE})
2757     public Function getOnclose() {
2758         return getEventHandler(Event.TYPE_CLOSE);
2759     }
2760 
2761     /**
2762      * Sets the {@code onclose} event handler.
2763      * @param onclose the {@code onclose} event handler
2764      */
2765     @JsxSetter({CHROME, EDGE})
2766     public void setOnclose(final Object onclose) {
2767         setHandlerForJavaScript(Event.TYPE_CLOSE, onclose);
2768     }
2769 
2770     /**
2771      * Returns the {@code onanimationend} event handler.
2772      * @return the {@code onanimationend} event handler
2773      */
2774     @JsxGetter
2775     public Function getOnanimationend() {
2776         return getEventHandler(Event.TYPE_ANIMATIONEND);
2777     }
2778 
2779     /**
2780      * Sets the {@code onanimationend} event handler.
2781      * @param onanimationend the {@code onanimationend} event handler
2782      */
2783     @JsxSetter
2784     public void setOnanimationend(final Object onanimationend) {
2785         setHandlerForJavaScript(Event.TYPE_ANIMATIONEND, onanimationend);
2786     }
2787 
2788     /**
2789      * Returns the {@code ondragenter} event handler.
2790      * @return the {@code ondragenter} event handler
2791      */
2792     @JsxGetter
2793     public Function getOndragenter() {
2794         return getEventHandler(Event.TYPE_DRAGENTER);
2795     }
2796 
2797     /**
2798      * Sets the {@code ondragenter} event handler.
2799      * @param ondragenter the {@code ondragenter} event handler
2800      */
2801     @JsxSetter
2802     public void setOndragenter(final Object ondragenter) {
2803         setHandlerForJavaScript(Event.TYPE_DRAGENTER, ondragenter);
2804     }
2805 
2806     /**
2807      * Returns the {@code onafterprint} event handler.
2808      * @return the {@code onafterprint} event handler
2809      */
2810     @JsxGetter({FF, FF_ESR})
2811     public Function getOnafterprint() {
2812         return getEventHandler(Event.TYPE_AFTERPRINT);
2813     }
2814 
2815     /**
2816      * Sets the {@code onafterprint} event handler.
2817      * @param onafterprint the {@code onafterprint} event handler
2818      */
2819     @JsxSetter({FF, FF_ESR})
2820     public void setOnafterprint(final Object onafterprint) {
2821         setHandlerForJavaScript(Event.TYPE_AFTERPRINT, onafterprint);
2822     }
2823 
2824     /**
2825      * Returns the {@code onmozfullscreenerror} event handler.
2826      * @return the {@code onmozfullscreenerror} event handler
2827      */
2828     @JsxGetter({FF, FF_ESR})
2829     public Function getOnmozfullscreenerror() {
2830         return getEventHandler(Event.TYPE_MOZFULLSCREENERROR);
2831     }
2832 
2833     /**
2834      * Sets the {@code onmozfullscreenerror} event handler.
2835      * @param onmozfullscreenerror the {@code onmozfullscreenerror} event handler
2836      */
2837     @JsxSetter({FF, FF_ESR})
2838     public void setOnmozfullscreenerror(final Object onmozfullscreenerror) {
2839         setHandlerForJavaScript(Event.TYPE_MOZFULLSCREENERROR, onmozfullscreenerror);
2840     }
2841 
2842     /**
2843      * Returns the {@code onmouseleave} event handler.
2844      * @return the {@code onmouseleave} event handler
2845      */
2846     @JsxGetter
2847     public Function getOnmouseleave() {
2848         return getEventHandler(Event.TYPE_MOUSELEAVE);
2849     }
2850 
2851     /**
2852      * Sets the {@code onmouseleave} event handler.
2853      * @param onmouseleave the {@code onmouseleave} event handler
2854      */
2855     @JsxSetter
2856     public void setOnmouseleave(final Object onmouseleave) {
2857         setHandlerForJavaScript(Event.TYPE_MOUSELEAVE, onmouseleave);
2858     }
2859 
2860     /**
2861      * Returns the {@code onmousewheel} event handler.
2862      * @return the {@code onmousewheel} event handler
2863      */
2864     @JsxGetter({CHROME, EDGE})
2865     public Function getOnmousewheel() {
2866         return getEventHandler(Event.TYPE_MOUSEWHEEL);
2867     }
2868 
2869     /**
2870      * Sets the {@code onmousewheel} event handler.
2871      * @param onmousewheel the {@code onmousewheel} event handler
2872      */
2873     @JsxSetter({CHROME, EDGE})
2874     public void setOnmousewheel(final Object onmousewheel) {
2875         setHandlerForJavaScript(Event.TYPE_MOUSEWHEEL, onmousewheel);
2876     }
2877 
2878     /**
2879      * Returns the {@code onseeking} event handler.
2880      * @return the {@code onseeking} event handler
2881      */
2882     @JsxGetter
2883     public Function getOnseeking() {
2884         return getEventHandler(Event.TYPE_SEEKING);
2885     }
2886 
2887     /**
2888      * Sets the {@code onseeking} event handler.
2889      * @param onseeking the {@code onseeking} event handler
2890      */
2891     @JsxSetter
2892     public void setOnseeking(final Object onseeking) {
2893         setHandlerForJavaScript(Event.TYPE_SEEKING, onseeking);
2894     }
2895 
2896     /**
2897      * Returns the {@code oncuechange} event handler.
2898      * @return the {@code oncuechange} event handler
2899      */
2900     @JsxGetter({CHROME, EDGE})
2901     public Function getOncuechange() {
2902         return getEventHandler(Event.TYPE_CUECHANGE);
2903     }
2904 
2905     /**
2906      * Sets the {@code oncuechange} event handler.
2907      * @param oncuechange the {@code oncuechange} event handler
2908      */
2909     @JsxSetter({CHROME, EDGE})
2910     public void setOncuechange(final Object oncuechange) {
2911         setHandlerForJavaScript(Event.TYPE_CUECHANGE, oncuechange);
2912     }
2913 
2914     /**
2915      * Returns the {@code onpageshow} event handler.
2916      * @return the {@code onpageshow} event handler
2917      */
2918     @JsxGetter
2919     public Function getOnpageshow() {
2920         return getEventHandler(Event.TYPE_PAGESHOW);
2921     }
2922 
2923     /**
2924      * Sets the {@code onpageshow} event handler.
2925      * @param onpageshow the {@code onpageshow} event handler
2926      */
2927     @JsxSetter
2928     public void setOnpageshow(final Object onpageshow) {
2929         setHandlerForJavaScript(Event.TYPE_PAGESHOW, onpageshow);
2930     }
2931 
2932     /**
2933      * Returns the {@code onmozfullscreenchange} event handler.
2934      * @return the {@code onmozfullscreenchange} event handler
2935      */
2936     @JsxGetter({FF, FF_ESR})
2937     public Function getOnmozfullscreenchange() {
2938         return getEventHandler(Event.TYPE_MOZFULLSCREENCHANGE);
2939     }
2940 
2941     /**
2942      * Sets the {@code onmozfullscreenchange} event handler.
2943      * @param onmozfullscreenchange the {@code onmozfullscreenchange} event handler
2944      */
2945     @JsxSetter({FF, FF_ESR})
2946     public void setOnmozfullscreenchange(final Object onmozfullscreenchange) {
2947         setHandlerForJavaScript(Event.TYPE_MOZFULLSCREENCHANGE, onmozfullscreenchange);
2948     }
2949 
2950     /**
2951      * Returns the {@code ondurationchange} event handler.
2952      * @return the {@code ondurationchange} event handler
2953      */
2954     @JsxGetter
2955     public Function getOndurationchange() {
2956         return getEventHandler(Event.TYPE_DURATIONCHANGE);
2957     }
2958 
2959     /**
2960      * Sets the {@code ondurationchange} event handler.
2961      * @param ondurationchange the {@code ondurationchange} event handler
2962      */
2963     @JsxSetter
2964     public void setOndurationchange(final Object ondurationchange) {
2965         setHandlerForJavaScript(Event.TYPE_DURATIONCHANGE, ondurationchange);
2966     }
2967 
2968     /**
2969      * Returns the {@code onplaying} event handler.
2970      * @return the {@code onplaying} event handler
2971      */
2972     @JsxGetter
2973     public Function getOnplaying() {
2974         return getEventHandler(Event.TYPE_PLAYING);
2975     }
2976 
2977     /**
2978      * Sets the {@code onplaying} event handler.
2979      * @param onplaying the {@code onplaying} event handler
2980      */
2981     @JsxSetter
2982     public void setOnplaying(final Object onplaying) {
2983         setHandlerForJavaScript(Event.TYPE_PLAYING, onplaying);
2984     }
2985 
2986     /**
2987      * Returns the {@code onended} event handler.
2988      * @return the {@code onended} event handler
2989      */
2990     @JsxGetter
2991     public Function getOnended() {
2992         return getEventHandler(Event.TYPE_ENDED);
2993     }
2994 
2995     /**
2996      * Sets the {@code onended} event handler.
2997      * @param onended the {@code onended} event handler
2998      */
2999     @JsxSetter
3000     public void setOnended(final Object onended) {
3001         setHandlerForJavaScript(Event.TYPE_ENDED, onended);
3002     }
3003 
3004     /**
3005      * Returns the {@code onloadeddata} event handler.
3006      * @return the {@code onloadeddata} event handler
3007      */
3008     @JsxGetter
3009     public Function getOnloadeddata() {
3010         return getEventHandler(Event.TYPE_LOADEDDATA);
3011     }
3012 
3013     /**
3014      * Sets the {@code onloadeddata} event handler.
3015      * @param onloadeddata the {@code onloadeddata} event handler
3016      */
3017     @JsxSetter
3018     public void setOnloadeddata(final Object onloadeddata) {
3019         setHandlerForJavaScript(Event.TYPE_LOADEDDATA, onloadeddata);
3020     }
3021 
3022     /**
3023      * Returns the {@code onunhandledrejection} event handler.
3024      * @return the {@code onunhandledrejection} event handler
3025      */
3026     @JsxGetter({CHROME, EDGE})
3027     public Function getOnunhandledrejection() {
3028         return getEventHandler(Event.TYPE_UNHANDLEDREJECTION);
3029     }
3030 
3031     /**
3032      * Sets the {@code onunhandledrejection} event handler.
3033      * @param onunhandledrejection the {@code onunhandledrejection} event handler
3034      */
3035     @JsxSetter({CHROME, EDGE})
3036     public void setOnunhandledrejection(final Object onunhandledrejection) {
3037         setHandlerForJavaScript(Event.TYPE_UNHANDLEDREJECTION, onunhandledrejection);
3038     }
3039 
3040     /**
3041      * Returns the {@code onmouseout} event handler.
3042      * @return the {@code onmouseout} event handler
3043      */
3044     @JsxGetter
3045     public Function getOnmouseout() {
3046         return getEventHandler(MouseEvent.TYPE_MOUSE_OUT);
3047     }
3048 
3049     /**
3050      * Sets the {@code onmouseout} event handler.
3051      * @param onmouseout the {@code onmouseout} event handler
3052      */
3053     @JsxSetter
3054     public void setOnmouseout(final Object onmouseout) {
3055         setHandlerForJavaScript(MouseEvent.TYPE_MOUSE_OUT, onmouseout);
3056     }
3057 
3058     /**
3059      * Returns the {@code onsuspend} event handler.
3060      * @return the {@code onsuspend} event handler
3061      */
3062     @JsxGetter
3063     public Function getOnsuspend() {
3064         return getEventHandler(Event.TYPE_SUSPEND);
3065     }
3066 
3067     /**
3068      * Sets the {@code onsuspend} event handler.
3069      * @param onsuspend the {@code onsuspend} event handler
3070      */
3071     @JsxSetter
3072     public void setOnsuspend(final Object onsuspend) {
3073         setHandlerForJavaScript(Event.TYPE_SUSPEND, onsuspend);
3074     }
3075 
3076     /**
3077      * Returns the {@code onwaiting} event handler.
3078      * @return the {@code onwaiting} event handler
3079      */
3080     @JsxGetter
3081     public Function getOnwaiting() {
3082         return getEventHandler(Event.TYPE_WAITING);
3083     }
3084 
3085     /**
3086      * Sets the {@code onwaiting} event handler.
3087      * @param onwaiting the {@code onwaiting} event handler
3088      */
3089     @JsxSetter
3090     public void setOnwaiting(final Object onwaiting) {
3091         setHandlerForJavaScript(Event.TYPE_WAITING, onwaiting);
3092     }
3093 
3094     /**
3095      * Returns the {@code oncanplay} event handler.
3096      * @return the {@code oncanplay} event handler
3097      */
3098     @JsxGetter
3099     public Function getOncanplay() {
3100         return getEventHandler(Event.TYPE_CANPLAY);
3101     }
3102 
3103     /**
3104      * Sets the {@code oncanplay} event handler.
3105      * @param oncanplay the {@code oncanplay} event handler
3106      */
3107     @JsxSetter
3108     public void setOncanplay(final Object oncanplay) {
3109         setHandlerForJavaScript(Event.TYPE_CANPLAY, oncanplay);
3110     }
3111 
3112     /**
3113      * Returns the {@code onmousedown} event handler.
3114      * @return the {@code onmousedown} event handler
3115      */
3116     @JsxGetter
3117     public Function getOnmousedown() {
3118         return getEventHandler(MouseEvent.TYPE_MOUSE_DOWN);
3119     }
3120 
3121     /**
3122      * Sets the {@code onmousedown} event handler.
3123      * @param onmousedown the {@code onmousedown} event handler
3124      */
3125     @JsxSetter
3126     public void setOnmousedown(final Object onmousedown) {
3127         setHandlerForJavaScript(MouseEvent.TYPE_MOUSE_DOWN, onmousedown);
3128     }
3129 
3130     /**
3131      * Returns the {@code onlanguagechange} event handler.
3132      * @return the {@code onlanguagechange} event handler
3133      */
3134     @JsxGetter
3135     public Function getOnlanguagechange() {
3136         return getEventHandler(Event.TYPE_LANGUAGECHANGE);
3137     }
3138 
3139     /**
3140      * Sets the {@code onlanguagechange} event handler.
3141      * @param onlanguagechange the {@code onlanguagechange} event handler
3142      */
3143     @JsxSetter
3144     public void setOnlanguagechange(final Object onlanguagechange) {
3145         setHandlerForJavaScript(Event.TYPE_LANGUAGECHANGE, onlanguagechange);
3146     }
3147 
3148     /**
3149      * Returns the {@code onemptied} event handler.
3150      * @return the {@code onemptied} event handler
3151      */
3152     @JsxGetter
3153     public Function getOnemptied() {
3154         return getEventHandler(Event.TYPE_EMPTIED);
3155     }
3156 
3157     /**
3158      * Sets the {@code onemptied} event handler.
3159      * @param onemptied the {@code onemptied} event handler
3160      */
3161     @JsxSetter
3162     public void setOnemptied(final Object onemptied) {
3163         setHandlerForJavaScript(Event.TYPE_EMPTIED, onemptied);
3164     }
3165 
3166     /**
3167      * Returns the {@code onrejectionhandled} event handler.
3168      * @return the {@code onrejectionhandled} event handler
3169      */
3170     @JsxGetter({CHROME, EDGE})
3171     public Function getOnrejectionhandled() {
3172         return getEventHandler(Event.TYPE_REJECTIONHANDLED);
3173     }
3174 
3175     /**
3176      * Sets the {@code onrejectionhandled} event handler.
3177      * @param onrejectionhandled the {@code onrejectionhandled} event handler
3178      */
3179     @JsxSetter({CHROME, EDGE})
3180     public void setOnrejectionhandled(final Object onrejectionhandled) {
3181         setHandlerForJavaScript(Event.TYPE_REJECTIONHANDLED, onrejectionhandled);
3182     }
3183 
3184     /**
3185      * Returns the {@code onpointercancel} event handler.
3186      * @return the {@code onpointercancel} event handler
3187      */
3188     @JsxGetter({CHROME, EDGE})
3189     public Function getOnpointercancel() {
3190         return getEventHandler(Event.TYPE_POINTERCANCEL);
3191     }
3192 
3193     /**
3194      * Sets the {@code onpointercancel} event handler.
3195      * @param onpointercancel the {@code onpointercancel} event handler
3196      */
3197     @JsxSetter({CHROME, EDGE})
3198     public void setOnpointercancel(final Object onpointercancel) {
3199         setHandlerForJavaScript(Event.TYPE_POINTERCANCEL, onpointercancel);
3200     }
3201 
3202     /**
3203      * Returns the {@code onresize} event handler.
3204      * @return the {@code onresize} event handler
3205      */
3206     @JsxGetter
3207     public Function getOnresize() {
3208         return getEventHandler(Event.TYPE_RESIZE);
3209     }
3210 
3211     /**
3212      * Sets the {@code onresize} event handler.
3213      * @param onresize the {@code onresize} event handler
3214      */
3215     @JsxSetter
3216     public void setOnresize(final Object onresize) {
3217         setHandlerForJavaScript(Event.TYPE_RESIZE, onresize);
3218     }
3219 
3220     /**
3221      * Returns the {@code onpause} event handler.
3222      * @return the {@code onpause} event handler
3223      */
3224     @JsxGetter
3225     public Function getOnpause() {
3226         return getEventHandler(Event.TYPE_PAUSE);
3227     }
3228 
3229     /**
3230      * Sets the {@code onpause} event handler.
3231      * @param onpause the {@code onpause} event handler
3232      */
3233     @JsxSetter
3234     public void setOnpause(final Object onpause) {
3235         setHandlerForJavaScript(Event.TYPE_PAUSE, onpause);
3236     }
3237 
3238     /**
3239      * Returns the {@code onloadstart} event handler.
3240      * @return the {@code onloadstart} event handler
3241      */
3242     @JsxGetter
3243     public Function getOnloadstart() {
3244         return getEventHandler(Event.TYPE_LOAD_START);
3245     }
3246 
3247     /**
3248      * Sets the {@code onloadstart} event handler.
3249      * @param onloadstart the {@code onloadstart} event handler
3250      */
3251     @JsxSetter
3252     public void setOnloadstart(final Object onloadstart) {
3253         setHandlerForJavaScript(Event.TYPE_LOAD_START, onloadstart);
3254     }
3255 
3256     /**
3257      * Returns the {@code onprogress} event handler.
3258      * @return the {@code onprogress} event handler
3259      */
3260     @JsxGetter
3261     public Function getOnprogress() {
3262         return getEventHandler(Event.TYPE_PROGRESS);
3263     }
3264 
3265     /**
3266      * Sets the {@code onprogress} event handler.
3267      * @param onprogress the {@code onprogress} event handler
3268      */
3269     @JsxSetter
3270     public void setOnprogress(final Object onprogress) {
3271         setHandlerForJavaScript(Event.TYPE_PROGRESS, onprogress);
3272     }
3273 
3274     /**
3275      * Returns the {@code onpointerup} event handler.
3276      * @return the {@code onpointerup} event handler
3277      */
3278     @JsxGetter({CHROME, EDGE})
3279     public Function getOnpointerup() {
3280         return getEventHandler(Event.TYPE_POINTERUP);
3281     }
3282 
3283     /**
3284      * Sets the {@code onpointerup} event handler.
3285      * @param onpointerup the {@code onpointerup} event handler
3286      */
3287     @JsxSetter({CHROME, EDGE})
3288     public void setOnpointerup(final Object onpointerup) {
3289         setHandlerForJavaScript(Event.TYPE_POINTERUP, onpointerup);
3290     }
3291 
3292     /**
3293      * Returns the {@code onwheel} event handler.
3294      * @return the {@code onwheel} event handler
3295      */
3296     @JsxGetter
3297     public Function getOnwheel() {
3298         return getEventHandler(Event.TYPE_WHEEL);
3299     }
3300 
3301     /**
3302      * Sets the {@code onwheel} event handler.
3303      * @param onwheel the {@code onwheel} event handler
3304      */
3305     @JsxSetter
3306     public void setOnwheel(final Object onwheel) {
3307         setHandlerForJavaScript(Event.TYPE_WHEEL, onwheel);
3308     }
3309 
3310     /**
3311      * Returns the {@code onpointerleave} event handler.
3312      * @return the {@code onpointerleave} event handler
3313      */
3314     @JsxGetter({CHROME, EDGE})
3315     public Function getOnpointerleave() {
3316         return getEventHandler(Event.TYPE_POINTERLEAVE);
3317     }
3318 
3319     /**
3320      * Sets the {@code onpointerleave} event handler.
3321      * @param onpointerleave the {@code onpointerleave} event handler
3322      */
3323     @JsxSetter({CHROME, EDGE})
3324     public void setOnpointerleave(final Object onpointerleave) {
3325         setHandlerForJavaScript(Event.TYPE_POINTERLEAVE, onpointerleave);
3326     }
3327 
3328     /**
3329      * Returns the {@code onbeforeprint} event handler.
3330      * @return the {@code onbeforeprint} event handler
3331      */
3332     @JsxGetter({FF, FF_ESR})
3333     public Function getOnbeforeprint() {
3334         return getEventHandler(Event.TYPE_BEFOREPRINT);
3335     }
3336 
3337     /**
3338      * Sets the {@code onbeforeprint} event handler.
3339      * @param onbeforeprint the {@code onbeforeprint} event handler
3340      */
3341     @JsxSetter({FF, FF_ESR})
3342     public void setOnbeforeprint(final Object onbeforeprint) {
3343         setHandlerForJavaScript(Event.TYPE_BEFOREPRINT, onbeforeprint);
3344     }
3345 
3346     /**
3347      * Returns the {@code onstorage} event handler.
3348      * @return the {@code onstorage} event handler
3349      */
3350     @JsxGetter
3351     public Function getOnstorage() {
3352         return getEventHandler(Event.TYPE_STORAGE);
3353     }
3354 
3355     /**
3356      * Sets the {@code onstorage} event handler.
3357      * @param onstorage the {@code onstorage} event handler
3358      */
3359     @JsxSetter
3360     public void setOnstorage(final Object onstorage) {
3361         setHandlerForJavaScript(Event.TYPE_STORAGE, onstorage);
3362     }
3363 
3364     /**
3365      * Returns the {@code onanimationstart} event handler.
3366      * @return the {@code onanimationstart} event handler
3367      */
3368     @JsxGetter
3369     public Function getOnanimationstart() {
3370         return getEventHandler(Event.TYPE_ANIMATIONSTART);
3371     }
3372 
3373     /**
3374      * Sets the {@code onanimationstart} event handler.
3375      * @param onanimationstart the {@code onanimationstart} event handler
3376      */
3377     @JsxSetter
3378     public void setOnanimationstart(final Object onanimationstart) {
3379         setHandlerForJavaScript(Event.TYPE_ANIMATIONSTART, onanimationstart);
3380     }
3381 
3382     /**
3383      * Returns the {@code ontimeupdate} event handler.
3384      * @return the {@code ontimeupdate} event handler
3385      */
3386     @JsxGetter
3387     public Function getOntimeupdate() {
3388         return getEventHandler(Event.TYPE_TIMEUPDATE);
3389     }
3390 
3391     /**
3392      * Sets the {@code ontimeupdate} event handler.
3393      * @param ontimeupdate the {@code ontimeupdate} event handler
3394      */
3395     @JsxSetter
3396     public void setOntimeupdate(final Object ontimeupdate) {
3397         setHandlerForJavaScript(Event.TYPE_TIMEUPDATE, ontimeupdate);
3398     }
3399 
3400     /**
3401      * Returns the {@code onpagehide} event handler.
3402      * @return the {@code onpagehide} event handler
3403      */
3404     @JsxGetter
3405     public Function getOnpagehide() {
3406         return getEventHandler(Event.TYPE_PAGEHIDE);
3407     }
3408 
3409     /**
3410      * Sets the {@code onpagehide} event handler.
3411      * @param onpagehide the {@code onpagehide} event handler
3412      */
3413     @JsxSetter
3414     public void setOnpagehide(final Object onpagehide) {
3415         setHandlerForJavaScript(Event.TYPE_PAGEHIDE, onpagehide);
3416     }
3417 
3418     /**
3419      * Returns the {@code onwebkitanimationiteration} event handler.
3420      * @return the {@code onwebkitanimationiteration} event handler
3421      */
3422     @JsxGetter({CHROME, EDGE})
3423     public Function getOnwebkitanimationiteration() {
3424         return getEventHandler(Event.TYPE_WEBKITANIMATIONITERATION);
3425     }
3426 
3427     /**
3428      * Sets the {@code onwebkitanimationiteration} event handler.
3429      * @param onwebkitanimationiteration the {@code onwebkitanimationiteration} event handler
3430      */
3431     @JsxSetter({CHROME, EDGE})
3432     public void setOnwebkitanimationiteration(final Object onwebkitanimationiteration) {
3433         setHandlerForJavaScript(Event.TYPE_WEBKITANIMATIONITERATION, onwebkitanimationiteration);
3434     }
3435 
3436     /**
3437      * Returns the {@code onabort} event handler.
3438      * @return the {@code onabort} event handler
3439      */
3440     @JsxGetter
3441     public Function getOnabort() {
3442         return getEventHandler(Event.TYPE_ABORT);
3443     }
3444 
3445     /**
3446      * Sets the {@code onabort} event handler.
3447      * @param onabort the {@code onabort} event handler
3448      */
3449     @JsxSetter
3450     public void setOnabort(final Object onabort) {
3451         setHandlerForJavaScript(Event.TYPE_ABORT, onabort);
3452     }
3453 
3454     /**
3455      * Returns the {@code onloadedmetadata} event handler.
3456      * @return the {@code onloadedmetadata} event handler
3457      */
3458     @JsxGetter
3459     public Function getOnloadedmetadata() {
3460         return getEventHandler(Event.TYPE_LOADEDMETADATA);
3461     }
3462 
3463     /**
3464      * Sets the {@code onloadedmetadata} event handler.
3465      * @param onloadedmetadata the {@code onloadedmetadata} event handler
3466      */
3467     @JsxSetter
3468     public void setOnloadedmetadata(final Object onloadedmetadata) {
3469         setHandlerForJavaScript(Event.TYPE_LOADEDMETADATA, onloadedmetadata);
3470     }
3471 
3472     /**
3473      * Returns the {@code onmouseup} event handler.
3474      * @return the {@code onmouseup} event handler
3475      */
3476     @JsxGetter
3477     public Function getOnmouseup() {
3478         return getEventHandler(MouseEvent.TYPE_MOUSE_UP);
3479     }
3480 
3481     /**
3482      * Sets the {@code onmouseup} event handler.
3483      * @param onmouseup the {@code onmouseup} event handler
3484      */
3485     @JsxSetter
3486     public void setOnmouseup(final Object onmouseup) {
3487         setHandlerForJavaScript(MouseEvent.TYPE_MOUSE_UP, onmouseup);
3488     }
3489 
3490     /**
3491      * Returns the {@code ondragover} event handler.
3492      * @return the {@code ondragover} event handler
3493      */
3494     @JsxGetter
3495     public Function getOndragover() {
3496         return getEventHandler(Event.TYPE_DRAGOVER);
3497     }
3498 
3499     /**
3500      * Sets the {@code ondragover} event handler.
3501      * @param ondragover the {@code ondragover} event handler
3502      */
3503     @JsxSetter
3504     public void setOndragover(final Object ondragover) {
3505         setHandlerForJavaScript(Event.TYPE_DRAGOVER, ondragover);
3506     }
3507 
3508     /**
3509      * Returns the {@code ononline} event handler.
3510      * @return the {@code ononline} event handler
3511      */
3512     @JsxGetter
3513     public Function getOnonline() {
3514         return getEventHandler(Event.TYPE_ONLINE);
3515     }
3516 
3517     /**
3518      * Sets the {@code ononline} event handler.
3519      * @param ononline the {@code ononline} event handler
3520      */
3521     @JsxSetter
3522     public void setOnonline(final Object ononline) {
3523         setHandlerForJavaScript(Event.TYPE_ONLINE, ononline);
3524     }
3525 
3526     /**
3527      * Returns the {@code onsearch} event handler.
3528      * @return the {@code onsearch} event handler
3529      */
3530     @JsxGetter({CHROME, EDGE})
3531     public Function getOnsearch() {
3532         return getEventHandler(Event.TYPE_SEARCH);
3533     }
3534 
3535     /**
3536      * Sets the {@code onsearch} event handler.
3537      * @param onsearch the {@code onsearch} event handler
3538      */
3539     @JsxSetter({CHROME, EDGE})
3540     public void setOnsearch(final Object onsearch) {
3541         setHandlerForJavaScript(Event.TYPE_SEARCH, onsearch);
3542     }
3543 
3544     /**
3545      * Returns the {@code oninput} event handler.
3546      * @return the {@code oninput} event handler
3547      */
3548     @JsxGetter
3549     public Function getOninput() {
3550         return getEventHandler(Event.TYPE_INPUT);
3551     }
3552 
3553     /**
3554      * Sets the {@code oninput} event handler.
3555      * @param oninput the {@code oninput} event handler
3556      */
3557     @JsxSetter
3558     public void setOninput(final Object oninput) {
3559         setHandlerForJavaScript(Event.TYPE_INPUT, oninput);
3560     }
3561 
3562     /**
3563      * Returns the {@code onwebkittransitionend} event handler.
3564      * @return the {@code onwebkittransitionend} event handler
3565      */
3566     @JsxGetter({CHROME, EDGE})
3567     public Function getOnwebkittransitionend() {
3568         return getEventHandler(Event.TYPE_WEBKITTRANSITIONEND);
3569     }
3570 
3571     /**
3572      * Sets the {@code onwebkittransitionend} event handler.
3573      * @param onwebkittransitionend the {@code onwebkittransitionend} event handler
3574      */
3575     @JsxSetter({CHROME, EDGE})
3576     public void setOnwebkittransitionend(final Object onwebkittransitionend) {
3577         setHandlerForJavaScript(Event.TYPE_WEBKITTRANSITIONEND, onwebkittransitionend);
3578     }
3579 
3580     /**
3581      * Returns the {@code ondevicemotion} event handler.
3582      * @return the {@code ondevicemotion} event handler
3583      */
3584     @JsxGetter
3585     public Function getOndevicemotion() {
3586         return getEventHandler(Event.TYPE_DEVICEMOTION);
3587     }
3588 
3589     /**
3590      * Sets the {@code ondevicemotion} event handler.
3591      * @param ondevicemotion the {@code ondevicemotion} event handler
3592      */
3593     @JsxSetter
3594     public void setOndevicemotion(final Object ondevicemotion) {
3595         setHandlerForJavaScript(Event.TYPE_DEVICEMOTION, ondevicemotion);
3596     }
3597 
3598     /**
3599      * Returns the {@code onstalled} event handler.
3600      * @return the {@code onstalled} event handler
3601      */
3602     @JsxGetter
3603     public Function getOnstalled() {
3604         return getEventHandler(Event.TYPE_STALLED);
3605     }
3606 
3607     /**
3608      * Sets the {@code onstalled} event handler.
3609      * @param onstalled the {@code onstalled} event handler
3610      */
3611     @JsxSetter
3612     public void setOnstalled(final Object onstalled) {
3613         setHandlerForJavaScript(Event.TYPE_STALLED, onstalled);
3614     }
3615 
3616     /**
3617      * Returns the {@code onmouseenter} event handler.
3618      * @return the {@code onmouseenter} event handler
3619      */
3620     @JsxGetter
3621     public Function getOnmouseenter() {
3622         return getEventHandler(Event.TYPE_MOUDEENTER);
3623     }
3624 
3625     /**
3626      * Sets the {@code onmouseenter} event handler.
3627      * @param onmouseenter the {@code onmouseenter} event handler
3628      */
3629     @JsxSetter
3630     public void setOnmouseenter(final Object onmouseenter) {
3631         setHandlerForJavaScript(Event.TYPE_MOUDEENTER, onmouseenter);
3632     }
3633 
3634     /**
3635      * Returns the {@code ondragleave} event handler.
3636      * @return the {@code ondragleave} event handler
3637      */
3638     @JsxGetter
3639     public Function getOndragleave() {
3640         return getEventHandler(Event.TYPE_DRAGLEAVE);
3641     }
3642 
3643     /**
3644      * Sets the {@code ondragleave} event handler.
3645      * @param ondragleave the {@code ondragleave} event handler
3646      */
3647     @JsxSetter
3648     public void setOndragleave(final Object ondragleave) {
3649         setHandlerForJavaScript(Event.TYPE_DRAGLEAVE, ondragleave);
3650     }
3651 
3652     /**
3653      * Returns the {@code onpointerdown} event handler.
3654      * @return the {@code onpointerdown} event handler
3655      */
3656     @JsxGetter({CHROME, EDGE})
3657     public Function getOnpointerdown() {
3658         return getEventHandler(Event.TYPE_POINTERDOWN);
3659     }
3660 
3661     /**
3662      * Sets the {@code onpointerdown} event handler.
3663      * @param onpointerdown the {@code onpointerdown} event handler
3664      */
3665     @JsxSetter({CHROME, EDGE})
3666     public void setOnpointerdown(final Object onpointerdown) {
3667         setHandlerForJavaScript(Event.TYPE_POINTERDOWN, onpointerdown);
3668     }
3669 
3670     /**
3671      * Returns the {@code ondrop} event handler.
3672      * @return the {@code ondrop} event handler
3673      */
3674     @JsxGetter
3675     public Function getOndrop() {
3676         return getEventHandler(Event.TYPE_DROP);
3677     }
3678 
3679     /**
3680      * Sets the {@code ondrop} event handler.
3681      * @param ondrop the {@code ondrop} event handler
3682      */
3683     @JsxSetter
3684     public void setOndrop(final Object ondrop) {
3685         setHandlerForJavaScript(Event.TYPE_DROP, ondrop);
3686     }
3687 
3688     /**
3689      * Returns the {@code onunload} event handler.
3690      * @return the {@code onunload} event handler
3691      */
3692     @JsxGetter
3693     public Function getOnunload() {
3694         return getEventHandler(Event.TYPE_UNLOAD);
3695     }
3696 
3697     /**
3698      * Sets the {@code onunload} event handler.
3699      * @param onunload the {@code onunload} event handler
3700      */
3701     @JsxSetter
3702     public void setOnunload(final Object onunload) {
3703         setHandlerForJavaScript(Event.TYPE_UNLOAD, onunload);
3704     }
3705 
3706     /**
3707      * Returns the {@code onwebkitanimationend} event handler.
3708      * @return the {@code onwebkitanimationend} event handler
3709      */
3710     @JsxGetter({CHROME, EDGE})
3711     public Function getOnwebkitanimationend() {
3712         return getEventHandler(Event.TYPE_WEBKITANIMATIONEND);
3713     }
3714 
3715     /**
3716      * Sets the {@code onwebkitanimationend} event handler.
3717      * @param onwebkitanimationend the {@code onwebkitanimationend} event handler
3718      */
3719     @JsxSetter({CHROME, EDGE})
3720     public void setOnwebkitanimationend(final Object onwebkitanimationend) {
3721         setHandlerForJavaScript(Event.TYPE_WEBKITANIMATIONEND, onwebkitanimationend);
3722     }
3723 
3724     /**
3725      * Returns the {@code ondragstart} event handler.
3726      * @return the {@code ondragstart} event handler
3727      */
3728     @JsxGetter
3729     public Function getOndragstart() {
3730         return getEventHandler(Event.TYPE_DRAGSTART);
3731     }
3732 
3733     /**
3734      * Sets the {@code ondragstart} event handler.
3735      * @param ondragstart the {@code ondragstart} event handler
3736      */
3737     @JsxSetter
3738     public void setOndragstart(final Object ondragstart) {
3739         setHandlerForJavaScript(Event.TYPE_DRAGSTART, ondragstart);
3740     }
3741 
3742     /**
3743      * Returns the {@code ontransitionend} event handler.
3744      * @return the {@code ontransitionend} event handler
3745      */
3746     @JsxGetter({CHROME, EDGE})
3747     public Function getOntransitionend() {
3748         return getEventHandler(Event.TYPE_TRANSITIONEND);
3749     }
3750 
3751     /**
3752      * Sets the {@code ontransitionend} event handler.
3753      * @param ontransitionend the {@code ontransitionend} event handler
3754      */
3755     @JsxSetter({CHROME, EDGE})
3756     public void setOntransitionend(final Object ontransitionend) {
3757         setHandlerForJavaScript(Event.TYPE_TRANSITIONEND, ontransitionend);
3758     }
3759 
3760     /**
3761      * Returns the {@code ondeviceorientationabsolute} event handler.
3762      * @return the {@code ondeviceorientationabsolute} event handler
3763      */
3764     @JsxGetter({CHROME, EDGE})
3765     public Function getOndeviceorientationabsolute() {
3766         return getEventHandler(Event.TYPE_DEVICEORIENTATIONABSOLUTE);
3767     }
3768 
3769     /**
3770      * Sets the {@code ondeviceorientationabsolute} event handler.
3771      * @param ondeviceorientationabsolute the {@code ondeviceorientationabsolute} event handler
3772      */
3773     @JsxSetter({CHROME, EDGE})
3774     public void setOndeviceorientationabsolute(final Object ondeviceorientationabsolute) {
3775         setHandlerForJavaScript(Event.TYPE_DEVICEORIENTATIONABSOLUTE, ondeviceorientationabsolute);
3776     }
3777 
3778     /**
3779      * Returns the {@code onvolumechange} event handler.
3780      * @return the {@code onvolumechange} event handler
3781      */
3782     @JsxGetter
3783     public Function getOnvolumechange() {
3784         return getEventHandler(Event.TYPE_VOLUMECHANGE);
3785     }
3786 
3787     /**
3788      * Sets the {@code onvolumechange} event handler.
3789      * @param onvolumechange the {@code onvolumechange} event handler
3790      */
3791     @JsxSetter
3792     public void setOnvolumechange(final Object onvolumechange) {
3793         setHandlerForJavaScript(Event.TYPE_VOLUMECHANGE, onvolumechange);
3794     }
3795 
3796     /**
3797      * Returns the {@code ongotpointercapture} event handler.
3798      * @return the {@code ongotpointercapture} event handler
3799      */
3800     @JsxGetter({CHROME, EDGE})
3801     public Function getOngotpointercapture() {
3802         return getEventHandler(Event.TYPE_GOTPOINTERCAPTURE);
3803     }
3804 
3805     /**
3806      * Sets the {@code ongotpointercapture} event handler.
3807      * @param ongotpointercapture the {@code ongotpointercapture} event handler
3808      */
3809     @JsxSetter({CHROME, EDGE})
3810     public void setOngotpointercapture(final Object ongotpointercapture) {
3811         setHandlerForJavaScript(Event.TYPE_GOTPOINTERCAPTURE, ongotpointercapture);
3812     }
3813 
3814     /**
3815      * Returns the {@code onpopstate} event handler.
3816      * @return the {@code onpopstate} event handler
3817      */
3818     @JsxGetter
3819     public Function getOnpopstate() {
3820         return getEventHandler(Event.TYPE_POPSTATE);
3821     }
3822 
3823     /**
3824      * Sets the {@code onpopstate} event handler.
3825      * @param onpopstate the {@code onpopstate} event handler
3826      */
3827     @JsxSetter
3828     public void setOnpopstate(final Object onpopstate) {
3829         setHandlerForJavaScript(Event.TYPE_POPSTATE, onpopstate);
3830     }
3831 
3832     /**
3833      * {@inheritDoc}
3834      * optimized version
3835      */
3836     @Override
3837     public BrowserVersion getBrowserVersion() {
3838         return getWebWindow().getWebClient().getBrowserVersion();
3839     }
3840 
3841     @Override
3842     public void put(final String name, final Scriptable start, final Object value) {
3843         // see https://dom.spec.whatwg.org/#window-current-event
3844         // because event is replaceable we need this hack here
3845         if ("event".equals(name)) {
3846             final Slot slot = querySlot(Context.getCurrentContext(), "event");
3847             if (slot instanceof AccessorSlot) {
3848                 delete("event");
3849             }
3850         }
3851         super.put(name, start, value);
3852     }
3853 
3854     /**
3855      * Returns a boolean indicating whether the current context is secure (true) or not (false).
3856      * @return a boolean indicating whether the current context is secure (true) or not (false).
3857      */
3858     @JsxGetter
3859     public boolean isIsSecureContext() {
3860         final Page page = getWebWindow().getEnclosedPage();
3861         if (page != null) {
3862             final String protocol = page.getUrl().getProtocol();
3863             if ("https".equals(protocol)
3864                     || "wss".equals(protocol)
3865                     || "file".equals(protocol)) {
3866                 return true;
3867             }
3868 
3869             final String host = page.getUrl().getHost();
3870             if ("localhost".equals(host)
3871                     || "localhost.".equals(host)
3872                     || host.endsWith(".localhost")
3873                     || host.endsWith(".localhost.")) {
3874                 return true;
3875             }
3876         }
3877 
3878         return false;
3879     }
3880 }
3881 
3882 class HTMLCollectionFrames extends HTMLCollection {
3883     private static final Log LOG = LogFactory.getLog(HTMLCollectionFrames.class);
3884 
3885     HTMLCollectionFrames(final HtmlPage page) {
3886         super(page, false);
3887         this.setIsMatchingPredicate((Predicate<DomNode> & Serializable) node -> node instanceof BaseFrameElement);
3888     }
3889 
3890     @Override
3891     protected Scriptable getScriptableForElement(final Object obj) {
3892         final WebWindow window;
3893         if (obj instanceof BaseFrameElement element) {
3894             window = element.getEnclosedWindow();
3895         }
3896         else {
3897             window = ((FrameWindow) obj).getFrameElement().getEnclosedWindow();
3898         }
3899 
3900         return window.getScriptableObject();
3901     }
3902 
3903     @Override
3904     protected Object getWithPreemption(final String name) {
3905         final List<DomNode> elements = getElements();
3906 
3907         for (final Object next : elements) {
3908             final BaseFrameElement frameElt = (BaseFrameElement) next;
3909             final WebWindow window = frameElt.getEnclosedWindow();
3910             if (name.equals(window.getName())) {
3911                 if (LOG.isDebugEnabled()) {
3912                     LOG.debug("Property \"" + name + "\" evaluated (by name) to " + window);
3913                 }
3914                 return getScriptableForElement(window);
3915             }
3916         }
3917 
3918         return NOT_FOUND;
3919     }
3920 }