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.
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
Navigator.share | โ 128+ | โ 93+ | โ flag only | โ 12.1+ | โ 12.2+ | Limited |
Navigator.canShare | โ 128+ | โ 93+ | โ flag only | โ 14+ | โ 14+ | Limited |
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: Navigator.share ยท Navigator.canShare
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.