Reading clipboard from the background page doesn't work

NEW
Assigned to

Status

()

Toolkit
WebExtensions: General
P2
normal
3 months ago
2 months ago

People

(Reporter: zombie, Assigned: zombie)

Tracking

unspecified
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: triaged)

(Assignee)

Description

3 months ago
See Andy's example https://github.com/andymckay/clippy
(Assignee)

Comment 1

3 months ago
Will investigate what's the difference between this and our tests.
Assignee: nobody → tomica

Updated

2 months ago
webextensions: --- → ?
Priority: -- → P2
Whiteboard: triaged
(Assignee)

Comment 2

2 months ago
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.

Comment 3

2 months ago
I can't get copy to work by using a background page with remote set to true, in Nightly on Windows.

Comment 4

2 months ago
I'm an idiot, I was setting the value in the wrong browser. Ignore my last comment.
You need to log in before you can comment on or make changes to this bug.