       # Firefox doesn't support createShadowRoot, so guard against its non-existance.
       # https://hacks.mozilla.org/2018/10/firefox-63-tricks-and-treats/ says
       # Firefox 63 has enabled Shadow DOM v1 by default
-      @shadowDOM = shadowWrapper.attachShadow?( mode: "open" ) ?
-        shadowWrapper.createShadowRoot?() ? shadowWrapper
+      if shadowWrapper.attachShadow
+        @shadowDOM = shadowWrapper.attachShadow(mode: "open")
+      else
+        @shadowArrwap = shadowWrapper
       @shadowDOM.appendChild styleSheet
       @shadowDOM.appendChild @iframeElement
       @toggleIframeElementClasses "vimiumUIComponentVisible", "vimiumUIComponentHidden"

            { port1, port2 } = new MessageChannel
            @iframeElement.contentWindow.postMessage vimiumSecret, chrome.runtime.getURL(""), [ port2 ]
            port1.onmessage = (event) =>
              switch event?.data?.name ? event?.data
                when "uiComponentIsReady"
                  # If any other frame receives the focus, then hide the UI component.
                  chrome.runtime.onMessage.addListener ({name, focusFrameId}) =>
                    if name == "frameFocused" and @options?.focus and focusFrameId not in [frameId, @iframeFrameId]
                      @hide false
                    false # We will not be calling sendResponse.
                  # If this frame receives the focus, then hide the UI component.
                  window.addEventListener "focus", (forTrusted (event) =>
                    if event.target == window and @options?.focus
                      @hide false
                    true # Continue propagating the event.
                  ), true

class UIComponent

  constructor: (iframeUrl, className, @handleMessage) ->
    @iframeElement = null
    @iframePort = null
    @showing = false
    @iframeFrameId = null
    # TODO(philc): Make the @options object default to {} and remove the null checks.
    @options = null
    @shadowDOM = null

    DomUtils.documentReady =>
      styleSheet = DomUtils.createElement "style"
      styleSheet.type = "text/css"
