mgrubinger / blog

https://www.grooovinger.com/
MIT License
0 stars 0 forks source link

Mock navigator.share #25

Open mgrubinger opened 1 year ago

mgrubinger commented 1 year ago

date: '2021-01-20' short: For testing in non-secure environments

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");
  }})
}