Skip to main content
@capgo/capacitor-share-target Communication Open source

Share Target Capacitor plugin

Receive shared content from other apps - text, images, and files

Install

bun add @capgo/capacitor-share-target bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-share-target
  • pnpm add @capgo/capacitor-share-target
  • yarn add @capgo/capacitor-share-target

Guide

How to use Share Target in Capacitor

Using @capgo/capacitor-share-target

Capacitor Share Target Plugin interface.

Install

bun add @capgo/capacitor-share-target
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { CapacitorShareTarget } from '@capgo/capacitor-share-target';

API at a glance

Method Description
addListener Listen for shareReceived event.
removeAllListeners Remove all listeners for this plugin.
getPluginVersion Get the native Capacitor plugin version.

Examples

addListener()

Listen for shareReceived event.

import { CapacitorShareTarget } from '@capgo/capacitor-share-target';

const listener = await CapacitorShareTarget.addListener('shareReceived', (event) => {
  console.log('Title:', event.title);
  console.log('Texts:', event.texts);
  event.files?.forEach(file => {
    console.log(`File: ${file.name} (${file.mimeType})`);
  });
});

// To remove the listener:
await listener.remove();

removeAllListeners()

Remove all listeners for this plugin.

import { CapacitorShareTarget } from '@capgo/capacitor-share-target';

await CapacitorShareTarget.removeAllListeners();

getPluginVersion()

Get the native Capacitor plugin version.

import { CapacitorShareTarget } from '@capgo/capacitor-share-target';

const { version} = await CapacitorShareTarget.getPluginVersion();
console.log('Plugin version:', version);

Listen to events

addListener returns a handle. Call handle.remove() when the screen unmounts, or CapacitorShareTarget.removeAllListeners() to clear every listener.

Full reference

Keep going from Using @capgo/capacitor-share-target

If you are using Using @capgo/capacitor-share-target to plan native plugin work, connect it with @capgo/capacitor-share-target for the implementation detail in @capgo/capacitor-share-target, Getting Started for the implementation detail in Getting Started, Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins.

FAQ

Share Target plugin FAQ

How do I install the Share Target plugin in a Capacitor app?

Run "bun add @capgo/capacitor-share-target" (or "npm install @capgo/capacitor-share-target"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-share-target" in your app code.

Does @capgo/capacitor-share-target work with React, Vue and Angular?

Yes. Share Target is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-share-target support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-share-target free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-share-target/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Share Target without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Share Target changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo