Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Only synchronize clipboards if data was or is going to be sent #640

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/teleport/src/DesktopSession/useTdpClientCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function useTdpClientCanvas(props: Props) {

// Default TdpClientEvent.TDP_CLIPBOARD_DATA handler.
const onClipboardData = (clipboardData: ClipboardData) => {
if (enableClipboardSharing && document.hasFocus()) {
if (enableClipboardSharing && document.hasFocus() && clipboardData.data) {
navigator.clipboard.writeText(clipboardData.data);
}
};
Expand Down Expand Up @@ -142,9 +142,11 @@ export default function useTdpClientCanvas(props: Props) {
// We must check that the DOM is focused or navigator.clipboard.readText throws an error.
if (enableClipboardSharing && document.hasFocus()) {
navigator.clipboard.readText().then(text => {
cli.sendClipboardData({
data: text,
});
if (text) {
cli.sendClipboardData({
data: text,
});
}
});
}
};
Expand Down