Skip to content

Commit 955de06

Browse files
NI57721philc
authored andcommitted
Use Clipboard API instead of execCommand("Copy")
1 parent 998bab4 commit 955de06

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

content_scripts/hud.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const HUD = {
3737
// Force the re-computation of styles, so Chrome sends a visibility change message to the child frame.
3838
// See https://github.com/philc/vimium/pull/3277#issuecomment-487363284
3939

40-
// Allow to access the clipboard through iframes.
41-
this.hudUI.iframeElement.allow = "clipboard-read";
40+
// Allow to access to the clipboard through iframes.
41+
this.hudUI.iframeElement.allow = "clipboard-read; clipboard-write";
4242
getComputedStyle(this.hudUI.iframeElement).display;
4343
} else {
4444
this.hudUI.toggleIframeElementClasses("vimiumClickable", "vimiumNonClickable");

lib/clipboard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const Clipboard = {
99
},
1010

1111
// http://groups.google.com/group/chromium-extensions/browse_thread/thread/49027e7f3b04f68/f6ab2457dee5bf55
12-
copy({data}) {
12+
async copy({data}) {
1313
const textArea = this._createTextArea();
1414
textArea.value = data.replace(/\xa0/g, " ");
1515

1616
document.body.appendChild(textArea);
1717
textArea.select();
18-
document.execCommand("Copy");
18+
await navigator.clipboard.writeText(textArea.value);
1919
document.body.removeChild(textArea);
2020
},
2121

pages/hud.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ const handlers = {
142142
},
143143

144144
copyToClipboard(data) {
145-
Utils.setTimeout(TIME_TO_WAIT_FOR_IPC_MESSAGES, function() {
145+
Utils.setTimeout(TIME_TO_WAIT_FOR_IPC_MESSAGES, async function() {
146146
const focusedElement = document.activeElement;
147-
Clipboard.copy(data);
147+
await Clipboard.copy(data);
148148
if (focusedElement != null)
149149
focusedElement.focus();
150150
window.parent.focus();

0 commit comments

Comments
 (0)