Refactor copy logic to remove deprecated execCommand

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-17 04:55:45 +00:00
1 parent 84e7f50f96
commit 6d0bd25067
3 files changed
+112 -17

No files matched your search

+3 -13
View File
@@ -399,6 +399,7 @@ export class EmbedVideoModal {
return;
}
// Attempt to copy using the Clipboard API
if (navigator?.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(snippet);
@@ -409,24 +410,13 @@ export class EmbedVideoModal {
}
}
// Fallback: Select the text so the user can copy manually
const textarea = this.snippetTextarea;
textarea.focus();
textarea.select();
textarea.setSelectionRange(0, textarea.value.length);
let succeeded = false;
try {
succeeded = this.document.execCommand("copy");
} catch (error) {
logger.user.warn("Embed modal copy fallback failed.", error);
succeeded = false;
}
if (succeeded) {
this.callbacks.showSuccess("Embed code copied to clipboard!");
} else {
this.callbacks.showError("Unable to copy embed code. Please copy it manually.");
}
this.callbacks.showError("Unable to copy embed code. Please copy it manually.");
}
async open({ video, triggerElement } = {}) {