Closed Bug 1364708 Opened 8 years ago Closed 5 years ago

Update test code to reflect recommended way to read clipboard from the background page

Categories

(WebExtensions :: General, enhancement, P5)

enhancement

Tracking

(Not tracked)

RESOLVED WONTFIX
webextensions ?

People

(Reporter: zombie, Assigned: zombie)

Details

(Whiteboard: triaged)

Will investigate what's the difference between this and our tests.
Assignee: nobody → tomica
webextensions: --- → ?
Priority: -- → P2
Whiteboard: triaged
So, it turns out a <textarea>, contentEditable and .value DOM property don't mix very well, and .textContent should be used instead. This code works for me (with extensions.remote=true). let area = document.createElement("textarea"); area.contentEditable = true; document.body.appendChild(area); function paste() { area.textContent = ''; area.select(); console.log('Pre-paste: ' + area.value); console.log(document.execCommand("paste")); console.log('Post-paste: ' + area.value); } function copy(text) { area.textContent = text; area.select(); console.log('Pre-copy: ' + area.value); console.log(document.execCommand("copy")); console.log('Post-copy: ' + area.value); } This bug could be about updating our test to use the same (recommended) code, but that's likely a lower priority.
I can't get copy to work by using a background page with remote set to true, in Nightly on Windows.
I'm an idiot, I was setting the value in the wrong browser. Ignore my last comment.
Priority: P2 → P5
Summary: Reading clipboard from the background page doesn't work → Update test code to reflect recommended way to read clipboard from the background page
Product: Toolkit → WebExtensions
This is still needed. Can probably use the Clipboard Web API for the text part.

The existing tests use .value, which has been working for the past few years.

Setting .textContent would be equivalent to setting .defaultValue. That is not wrong, but it is not necessary either.

Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.