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

Closed
chriche-ms opened this issue Sep 10, 2024 · 1 comment
Closed
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@chriche-ms
Copy link

chriche-ms commented Sep 10, 2024

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

AB#54073971

@chriche-ms chriche-ms added the bug Something isn't working label Sep 10, 2024
@fabiorocha fabiorocha added the tracked We are tracking this work internally. label Sep 23, 2024
@victorhuangwq
Copy link
Collaborator

No longer repro in 129.0.2792.52

@victorhuangwq victorhuangwq closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 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 tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

4 participants