Skip to main content

webshare

Share text, links, or files via the platform's native share sheet, using the Web Share API.

Import: @rtorcato/browser-common/webshare

๐Ÿ“– MDN: Navigator: share() method ยท ๐Ÿ“Š caniuse: web-share

navigator.share needs a user gesture; wide support on mobile, but Firefox desktop never shipped it.

Exampleโ€‹

import {
isWebShareAvailable,
isFileShareAvailable,
share,
} from '@rtorcato/browser-common/webshare'

if (isWebShareAvailable()) {
await share({ title: 'Look', url: 'https://example.com' })
}

if (isFileShareAvailable()) {
await share({ files: [myFile] })
}

Exportsโ€‹

  • isWebShareAvailable() โ€” feature check
  • share(data) โ€” shares { title, text, url, files } via navigator.share; throws if unsupported
  • isFileShareAvailable() โ€” checks whether navigator.canShare supports sharing files

See the API reference for full signatures.