# Native share plugin

Source: https://saastostore.com/plugins/share

This plugin opens the phone's share sheet with a text, a link, or both, so people can send a page to any app they have. It handles text and links, not files. Don't confuse it with Receive shares, which lets other apps send content to yours.

## Set it up

1. **Add the plugin** In your project's plugin library, add Native share, then launch a new build.
2. **Connect your share buttons** Inside the app, call `share` rather than your web sharing code.

## JavaScript API

```js
const r = await window.saastostore?.share?.({
  title: "Trip to Lisbon",            // optional
  text: "Here is our itinerary",
  url: "https://example.com/trips/42",
});
// → { shared: true }    the share sheet opened
// → { shared: false, error: "invalid_argument" }   url not http or https
// share() with neither text nor url shares the page shown

// in a normal browser: navigator.share?.({ title, text, url })
```

| Argument | Meaning |
| --- | --- |
| `title` | Optional. The subject of an email, or the title of the sheet |
| `text` | The message |
| `url` | A link, `http` or `https` only |

`share` is a function, not an object. `shared: true` means the sheet opened, not that something was sent. Your code isn't told which app people chose.

## One button for app and web

```js
async function shareTrip(data) {
  if (window.saastostore?.share) return window.saastostore.share(data);
  if (navigator.share) return navigator.share(data);
  await navigator.clipboard.writeText(data.url); // last resort on desktop
}
```

## Prompt for AI builders

**Prompt for Lovable, Bolt or Base44**

```text
My website also runs inside a mobile app. Inside the app, window.saastostore?.share({ title, text, url }) opens the native share sheet. In a normal browser it doesn't exist, and nothing must change.

Make my share buttons call window.saastostore.share when it exists, navigator.share when it doesn't, and copy the link to the clipboard as a last resort. Its promise never rejects, so don't wrap it in a try/catch for the app case.
```

Then launch a new build if you haven't added the plugin yet.

## Frequently asked questions

### Can I share an image or a file?

Not with this plugin. It shares text and links. Link to a page that shows the image instead.

### Does navigator.share work in the app?

Web sharing isn't dependable inside a web view. Use window.saastostore.share in the app, and keep navigator.share for browsers.

### Can I know if the person really shared?

No. You only know the sheet opened. The system doesn't tell the app what happened next.
