Can't use Clipboard API after sending a message to the background script?

Hi,

I’m encountering an unexpected issue in Safari. Specifically, navigator.clipboard.writeText() fails when called from a content script in my extension immediately after sending a message to background.js while it works fine in Chrome and Firefox. Is this expected?

Environment

  • Safari
    • 18.2 (20620.1.16.11.8)
    • Technology Preview 210
  • macOS Sequoia 15.2 (24C101)

Example

This is a minimal reproducible example, which adds a button to example.com: https://github.com/mshibanami/ClipboarAPIIssueExample

Below is the related code:

// content.js
copyButton.addEventListener('click', async () => {
	// 👇️ This call seems to trigger the issue
  await chrome.runtime.sendMessage({});
	
  try {
    await navigator.clipboard.writeText(text);
    alert(`✅ Copied '${text}' to clipboard!`);
  } catch (err) {
    alert(err + '\n\n' + `navigator.userActivation.isActive: ${navigator.userActivation.isActive}`);
  }
});
// background.js
chrome.runtime.onMessage.addListener(() => { });

When I click the button, I expect the text to be copied successfully. However, I receive an error in Safari.:

Interestingly, if I remove chrome.runtime.sendMessage(), the clipboard operation works without any problems. Also, note that navigator.userActivation.isActive is true, which might mean it's not related to the User Activation API.

Misc.

This might be related to another question I posted here: https://developer.apple.com/forums/thread/772275

Can't use Clipboard API after sending a message to the background script?
 
 
Q