Copy to clipboard from calling app

I’m making a calling app and added a button that copies the incoming call’s number to the clipboard using navigator.clipboard.writeText. This works fine for FireFox, but on Chrome it get me this error:

Does HubSpot just not support this functionality?

Hi @JeroenCloudCTI.

Chrome blocks navigator.clipboard.writeText() whenever the iframe you’re running in hasn’t been granted the clipboard-write permission through the page’s Permissions-Policy header (or the allow attribute on the <iframe>).

The HubSpot calling-extension iframe is injected by HubSpot, and its feature-policy explicitly disallows clipboard access, so the API throws the “blocked because of a permissions policy applied to the current document” error. Firefox is looser here, which is why it works there.

You can’t override the header or add allow=“clipboard-write” from inside the extension, so the modern Clipboard API is off-limits in Chrome.

Work-around (still Chrome-safe): use the old execCommand trick inside a user-generated click handler.

function copyToClipboard(text) {
 const tmp = document.createElement('textarea');
 tmp.value = text;
 tmp.style.position = 'fixed'; // avoid scrolling jump
 tmp.style.opacity = '0';
 document.body.appendChild(tmp);
 tmp.select();
 document.execCommand('copy');
 document.body.removeChild(tmp);
}
button.addEventListener('click', () => copyToClipboard('+90…'));

Because document.execCommand(‘copy’) fires in direct response to a user click, Chrome treats it as a permitted clipboard write even without the new permission.

Until HubSpot exposes clipboard-write in the feature policy (no ETA on that), the execCommand fallback is the only reliable way to let reps copy data from a calling-extension UI.
Hope It Works.

RubenB_0-1744951380316.png

Ruben Burdin

Real-Time Data Sync Between any CRM or Database | Founder @Stacksync (YC W24)

Lovely, works like a charm!

Thank you for your answer and explanation @RubenBurdin