Capacitor 3 Clipboard Error

When opening a view and a component is trying to read from the Clipboard plugin, I’m getting a permission denied issue.

In v2, I was using the Permissions plugin to first make sure I had appropriate permissions, but now Permissions has been removed and those plugins that need permissions have the request functions baked in. However, unlike a few others, I’m not seeing requestPermissions() inside of the Clipboard plugin. It seems like it may be only an iOS thing? Maybe I’m just totally missing something. Any insight would be appreciated!

1 Like

Looks like you’re running this in the browser, what browser are you using?

Hey Mike, I’m running a PWA saved to home screen through Safari from iOS 14.4 Simulator.

Hi
running PWA on iOS device (not simulator) - iOS 14.4 and copy to clipboard works flawlessly



import { Plugins } from '@capacitor/core';
const { Clipboard } = Plugins;

   Clipboard.write({
      string: url
    });

Maybe because I use “@capacitor/core”: “2.4.7”,?

Yes, a similar setup was working for me as well until I moved to using:

...
"@capacitor/core": "^3.0.0-rc.0",
"@capacitor/clipboard": "^0.4.6",
...

I’ve been able to reproduce, it only happens the first time you call read or write, the next call works.

It happens because on iOS it requires user interaction, but on first call the plugin gets initialized and on the initialization it loses the user gesture somehow. On next calls, since the plugin is already initialized it works fine.

Will report an issue

Ok, awesome! I appreciate you guys digging into this!

july 8 2021, still happening on ionic lab

This was fixed in the Clipboard plugin long ago, I have no experience with ionic lab

On my Ionic App i have Capacitor 3.2.3, I developed a progressive web app, and CLIPBOARD doesn’t work on IOS only.

This is my code:

      Clipboard.write({string: this.deal.discountCodeSingle}).then(value => {
        console.log('Codice Sconto Copiato');
      });