Skip to content

Commit 22f0344

Browse files
committed
Fix a clipboard error in Vimium iframes in Chrome
Using link hints or copyCurrentUrl while the help dialog is showing triggered this error in Chrome. The extension got into a bad state on the page and required a refresh: Potential permissions policy violation: clipboard-read is not allowed in this document.
1 parent 1f01a2b commit 22f0344

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

content_scripts/hud.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ const HUD = {
4747
"vimium-hud-frame",
4848
this.handleUIComponentMessage.bind(this),
4949
);
50-
// Allow to access to the clipboard through iframes.
51-
// This is only valid/necessary for Chrome. Firefox will show this console warning:
52-
// 'Feature Policy: Skipping unsupported feature name "clipboard-read"'
53-
if (!Utils.isFirefox()) {
54-
this.hudUI.iframeElement.allow = "clipboard-read; clipboard-write";
55-
}
5650
}
5751
// this[data.name]? data
5852
if (this.tween == null) {

content_scripts/ui_component.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ class UIComponent {
3232
const isDomTests = iframeUrl.includes("?dom_tests=true");
3333
this.iframeElement = DomUtils.createElement("iframe");
3434

35+
// Allow Vimium's iframes to have clipboard access in Chrome. This is needed when triggering
36+
// some commands, like link hints or copyCurrentUrl, from within the help dialog. Firefox does
37+
// not support clipboard-read and clipboard-write in the allow attribute. NOTE(philc): this
38+
// permission has to be set before we append the iframe to the DOM, or Chrome will log the
39+
// console error "Potential permissions policy violation: clipboard-read is not allowed in this
40+
// document."
41+
if (!Utils.isFirefox()) {
42+
this.iframeElement.allow = "clipboard-read; clipboard-write";
43+
}
44+
3545
const styleSheet = DomUtils.createElement("style");
3646
styleSheet.type = "text/css";
3747
// Default to everything hidden while the stylesheet loads.

tests/unit_tests/ui_component_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as testHelper from "./test_helper.js";
2+
import "../../lib/utils.js";
23
import "../../lib/dom_utils.js";
34
import "../../content_scripts/ui_component.js";
45

@@ -17,6 +18,7 @@ context("UIComponent", () => {
1718
setup(async () => {
1819
// Which page we load doesn't matter; we just need any DOM.
1920
await testHelper.jsdomStub("pages/help_dialog_page.html");
21+
stub(Utils, "isFirefox", () => false);
2022
});
2123

2224
teardown(() => {

0 commit comments

Comments
 (0)