Mock navigator.share

2021-01-20

Sometimes you can’t test the native [Navigator.share()](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share) API, e.g. when the site you’re developing is not served via https.

I used this tiny logger to preview what would have been passed to navigator.share()

!navigator.share && navigator.share = (...args) => {
  return new Promise(() => {
    console.log(...args)
  , () => {
     console.log("error");
  }})
}