function ensureDomLoaded (func) {
  const isDocumentReady = ['interactive', 'complete'].includes(
    document.readyState
  )
  if (isDocumentReady) {
    func()
  } else {
    let triggered = false
    const onDomContentLoaded = () => {
      if (!triggered) {
        triggered = true
        setTimeout(func, 1)
      }
    }

    document.addEventListener('DOMContentLoaded', onDomContentLoaded)
  }
}
Waits for the DOM to be loaded before calling a function. This is used to prevent the script from running before the DOM is loaded. In mv3, this is not needed, as inserting this.ensure_dom = true in the constructor works in the same manner. However, the function is still available for backwards compatibility and for allowing other functions to work.
@param {function} f - The function to call.