Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: Clipboard write API doesn't support multiple mime types #4801

Open
chriche-ms opened this issue Sep 10, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@chriche-ms
Copy link

What happened?

Writing to the clipboard with multiple mime types does not work, only the last type is written to the clipboard.

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

128.0.2739.67

SDK Version

1.0.2592.51

Framework

Win32

Operating System

Windows 11

OS Version

22631.4037

Repro steps

function getClipboardBlob(text, type) {
  return new Blob([text], { type });
}

function getClipboardItems(text, html) {
  const typeText = "text/plain";
  const blobText = getClipboardBlob(text, typeText);

  const typeHtml = "text/html";
  const blobHtml = getClipboardBlob(html, typeHtml);

  const items = [
    new ClipboardItem({ [typeText]: blobText, [typeHtml]: blobHtml }),
  ];

  return items;
}

async function writeClipboardTextAsync(text) {
  try {
    const html = `<a href="${text}">Link!</a>`;

    await navigator.clipboard.write(getClipboardItems(text, html));
  } catch (error) {
    console.error(error.message);
  }
}

Using this code to write multiple mime types to the clipboard does not work as expected. Only one of the types is added to the clipboard (the expected behaviour is for both types to be added to the clipboard with applications that understand html content pasting the anchor element while other apps receive the plain text). Reading the clipboard contents directly after the write call shows only a single type returned from ClipboardItem.getTypes (the 'last' property in the object passed to the ClipboardItem constructor).

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

@chriche-ms chriche-ms added the bug Something isn't working label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants