Fix javascript error "window" is not an element.

Created on 29 August 2025, about 1 month ago

Problem/Motivation

I don't quite understand "drowl_admin.core_dialog_enhancements.js" is it still needed? It seems to not do anything for quite a while now, since window is not an element, so when e.g. triggering AJAX the following console error is thrown:

Uncaught TypeError: The element must be an instance of Element
at u (once.js:122:11)
at once.js:189:22
at Array.filter ()
at c (once.js:188:19)
at a (once.js:278:10)
at Object.attach (drowl_admin.core_dialog_enhancements.js?v=1.x:9:11)
at drupal.js?v=11.2.3:166:24
at Array.forEach ()
at Drupal.attachBehaviors (drupal.js?v=11.2.3:162:34)
at ajax.js?v=11.2.3:1137:20

since window is not an element and once can not operate on the "window" object.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany Grevil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Grevil
  • 🇩🇪Germany Grevil

    We could add:

            if (!(window instanceof Element)) {
              return;
            }
    

    But window will never be an element, meaning this whole js seems kind of useless?

  • 🇩🇪Germany Grevil
    (function ($, Drupal) {
      Drupal.behaviors.drowl_admin_core_dialog_enhancements = {
        attach: function (context, settings) {
          // Add body classes if a modal is currently opened or not.
          // We use them in drowl_admin.theme_overrides.gin.scss to block
          // disturbing body scrolling while a modal is opened.
          if ($(".webform-ajax-form-wrapper").length == 0) {
            // Exclude webform from this, they do weird things we wont support here.
            $(once("drowl-admin-core-dialog-enhancements", window)) // THIS ALWAYS FAILS
              .on("dialog:beforecreate", function () {
                $("body:first").addClass("drowl-admin--core-dialog-open");
              })
    

    (The code in question "drowl_admin.core_dialog_enhancements.js")

  • First commit to issue fork.
  • 🇩🇪Germany Anybody Porta Westfalica

    The once functions take 2 parameters, a string id without spaces and an array-like object. The recommended way to use it is to call it with the string you would use in a querySelectorAll() call. You can only use once with objects that are instances of Element, which means you can not use it with the document or window object. If you need a page-level element please use 'html' or 'body' as the selector used in the once call: once('my-global-once', 'html').

    https://www.drupal.org/node/3158256

  • @anybody opened merge request.
  • 🇩🇪Germany Anybody Porta Westfalica

    @thomas.frobieter please test if this works.

  • 🇩🇪Germany Anybody Porta Westfalica
  • It seems that GIN (or the core dialog.js) already prevents scrolling when the dialogue is open. Therefore, this fix is no longer required.

    I will remove the Javascript file and the corresponding CSS code.

  • Done. I'll create a new release.

Production build 0.71.5 2024