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 checkshare(data)โ shares{ title, text, url, files }vianavigator.share; throws if unsupportedisFileShareAvailable()โ checks whethernavigator.canSharesupports sharing files
See the API reference for full signatures.