export default async function overwriteClick() {
     /**
     * Attempt to scroll to element if it is not clickable.
     * Pass { force: true } to click with JS even if element is not visible or clickable.
     */
    // 'click'            - name of command to be overwritten
    // origClickFunction  - original click function
    await browser.overwriteCommand('click', async function (origClickFunction, { force = false } = {}) {
      if (!force) {
          try {
              // attempt to click
              return origClickFunction();
          } catch (err) {
              if (err.message.includes('not clickable at point')) {
                  console.warn('WARN: Element', this.selector, 'is not clickable.',
                      'Scrolling to it before clicking again.')

                  // scroll to element and click again
                  await this.scrollIntoView()
                  return origClickFunction()
              }
              throw err
          }
      }

      // clicking with js
      console.warn('WARN: Using force click for', this.selector)
      await browser.execute(async function (el) {
          await el.click()
      }, this)
    }, true) // don't forget to pass `true` as 3rd argument to apply command on elements
  }
