# document.execCommand("paste") not working on some page

**URL:** <https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739>\
**Category:** Development\
**Created:** [January 23, 2018, 1:36pm UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739 "2018-01-23T13:36:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rappazf](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rappazf](https://discourse.mozilla.org/u/rappazf)\
**Post date:** [January 23, 2018, 1:36pm UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/1 "2018-01-23T13:36:30Z")

</div>

With Nightly and FF 57.04 It seems that the command

`document.execCommand("paste");`

is not working on same page:

```
   area = document.createElement("textarea");
   area.setAttribute("id", "fcb_txt_area");
   if (field) {
       field.parentNode.append(area);
   } 
   else {
         document.body.appendChild(area); 
   }
   area.contentEditable = true;
   area.textContent = '';
   area.select();
   console.log('Pre-paste: ' + area.value);
   document.execCommand("paste");
   var value = area.value;
    console.log('Post-paste: ' + area.value);
    return value;

```

On these page the Post-paste value is empty.

Strangely it is not consistent: when I load a page the it does not work but it seems that if I run a  
`document.execCommand('copy', false, null);`  
on the same page using my extension without reloading, then the paste command succeed …

Any idea someone ?  
Thanks  
F

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [January 23, 2018, 2:00pm UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/2 "2018-01-23T14:00:07Z")

</div>

Where do you run the code you’re showing from? Since `document.executeCommand` has to be called from a user-action.

---

<div class="post-metadata">

**Author:** ![rappazf](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rappazf](https://discourse.mozilla.org/u/rappazf)\
**Post date:** [January 23, 2018, 2:06pm UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/3 "2018-01-23T14:06:42Z")

</div>

It’s run from a content script. Here is the manifest

```
{
   "background": {
      "scripts": ["js/storage.js", "js/background.js"]
   },
  
   "icons": {
       "16": "img/icon-16x16.png",
       "48": "img/icon-48x48.png"
   },
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
     "js": ["js/content.js"]
  }
],
   "manifest_version": 2,
 "description": " __MSG_panel_label__",
  "name": " __MSG_extName__",
   "permissions": ["storage", "contextMenus", "http://*/*", "https://*/*", "activeTab", "tabs","clipboardRead", "clipboardWrite"],
   "version": "0.0.2",
    "options_ui": {
		"page":"options.html"
     },
	"default_locale": "en",
 "applications": {
    "gecko": {
      "id": "skimtheclipboardy@rappazf.ch",
      "strict_min_version": "54.0"
    }
  },

	"commands": {
		"one": {
		"suggested_key": {
			"default": "Ctrl+Shift+U",
			"mac": "Command+Shift+U"
		},
		"description": "run shortkey one"
		},
	"two": {
		"suggested_key": {
			"default": "Ctrl+Shift+B",
			"mac": "Command+Shift+B"
		},
		"description": "run shortkey two"
	},	
	"three": {
		"suggested_key": {
			"default": "Ctrl+Shift+C",
			"mac": "Command+Shift+C"
		},
		"description": "run shortkey three"
	}
	}
 
}
```

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [January 23, 2018, 2:18pm UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/4 "2018-01-23T14:18:05Z")

</div>

So code’s the whole content of the content script?

---

<div class="post-metadata">

**Author:** ![rappazf](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rappazf](https://discourse.mozilla.org/u/rappazf)\
**Post date:** [January 23, 2018, 2:26pm UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/5 "2018-01-23T14:26:11Z")

</div>

You may test the extension  
[here](https://addons.mozilla.org/en-GB/firefox/addon/skim-the-clipboard/)

and [here](http://rzblx1.uni-regensburg.de/ezeit/fl.phtml?bibid=KUBFR&colors=7&lang=en) for example of a page that sometime fails

when using the extension to filter in pasting with \>4 in the search field on top of the page

content.js  
[https://sourceforge.net/p/skimtheclipboard4ff/code/ci/default/tree/js/content.js](https://sourceforge.net/p/skimtheclipboard4ff/code/ci/default/tree/js/content.js)

---

<div class="post-metadata">

**Author:** ![rappazf](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rappazf](https://discourse.mozilla.org/u/rappazf)\
**Post date:** [January 26, 2018, 6:59am UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/6 "2018-01-26T06:59:51Z")

</div>

I have made a simpler example that shows this behaviour  
content.js  
`
document.addEventListener(“keyup”, paste);`

function paste(){  
var field = document.activeElement;  
var area = document.getElementById(“paste\_area”);  
if (area) {  
// console.log(“Found existing area”);  
area.setAttribute(“style”, “visibility:visible;”);  
// area.setAttribute(“style”, “display:inline;”);  
}  
else {  
// console.log(“Creating new area”);  
area = document.createElement(“textarea”);  
area.setAttribute(“id”, “paste\_area”);  
if (field) {  
field.parentNode.append(area);  
}  
else {  
document.body.appendChild(area);  
}  
area.contentEditable = true;  
}

```
 area.select();
 area.textContent = '';
 console.log('Pre-paste: ' + area.value);
 console.log(document.execCommand("paste"));
 var value = area.value;
 console.log('Post-paste: ' + area.value);

```

}

manifest.json  
`
{
“description”: “get the clipboard content”,
“manifest_version”: 2,
“name”: “paste_test”,
“applications”: {
“gecko”: {
“id”: "paste_test@example.com"
}
},
“permissions”: [
“clipboardRead”,
“clipboardWrite”
],
“version”: “1.0”,
“browser_action”: {
“browser_style”: true,
“default_title”: “Paste_test”
},
“content_scripts”: [
{
“matches”: ["<all_urls>"],
“js”: [“content.js”]
}
]
}
`  
Open nigthly and load this test extension, open the console  
Now go to [http://rzblx1.uni-regensburg.de/ezeit/fl.phtml?bibid=KUBFR&colors=7&lang=en](http://rzblx1.uni-regensburg.de/ezeit/fl.phtml?bibid=KUBFR&colors=7&lang=en)  
Select some text on the page and right click to copy the selection in the clipboard  
Click in the search field  
Use the shift key to run a keyup event : no text is pasted, even if true is return on the console.  
Strangely if you open a empty notepad file, you paste there the clipboard content, reselect it and copy it again, the test works on the page…  
It seems that with copying a part of the text from the same page that I want to paste it, I lost the clipboard access.  
This behaviour is not show in all the page, for example in this page [http://www.unifr.ch/dokpe/en](http://www.unifr.ch/dokpe/en) a text copied from the page is always pasted in the custom google search field on the left.

I think I can fill a bug with that …

---

<div class="post-metadata">

**Author:** ![rappazf](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rappazf](https://discourse.mozilla.org/u/rappazf)\
**Post date:** [January 31, 2018, 7:28am UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/7 "2018-01-31T07:28:33Z")

</div>

[https://bugzilla.mozilla.org/show\_bug.cgi?id=1433371](https://bugzilla.mozilla.org/show_bug.cgi?id=1433371)

---

<div class="post-metadata">

**Author:** ![rappazf](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rappazf](https://discourse.mozilla.org/u/rappazf)\
**Post date:** [February 7, 2018, 6:36am UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/8 "2018-02-07T06:36:20Z")

</div>

Am I correct in saying that with a priority of P3 (backlog)!, this bug won’t be corrected in future releases of Firefox ?

F.

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [February 7, 2018, 8:31am UTC](https://discourse.mozilla.org/t/document-execcommand-paste-not-working-on-some-page/24739/9 "2018-02-07T08:31:37Z")

</div>

No. P3 means staff will get around to it, it just won’t be in the next dev cycles releases (so that’s 60 and 61) for staff. P5 would mean it would only happen if non-staff implemented it, however.
