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