;(function () {
  const previousRemoveChild = Node.prototype.removeChild
  Node.prototype.removeChild = function (child) {
    try {
      return previousRemoveChild.call(this, child)
    } catch (e) {
      if (e?.toString().includes('NotFoundError')) {
        return
      }
      throw e
    }
  }
  const previousInsertBefore = Node.prototype.insertBefore
  Node.prototype.insertBefore = function (newChild, refChild) {
    try {
      return previousInsertBefore.call(this, newChild, refChild)
    } catch (e) {
      if (e?.toString().includes('NotFoundError')) {
        return this.appendChild(newChild)
      }
      throw e
    }
  }
})()
