Open Bug 1494266 Opened 6 years ago Updated 2 years ago

Please extend the clipboard API with access to the X selection buffer

Categories

(Core :: XPCOM, enhancement, P5)

63 Branch
enhancement

Tracking

()

UNCONFIRMED

People

(Reporter: dam, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0
Build ID: 20100101

Steps to reproduce:

I have a web-extension that uses the clipboard's content to offer quick queries: https://addons.mozilla.org/en-US/firefox/addon/debian-buttons/

(All that follows is under X.org or Wayland under Debian/sid)

Upon activation, it does an automatic Paste in a text input. However, this gets the contents of the desktop environment's clipboard, and I'd like to be able to get the X selection instead (https://en.wikipedia.org/wiki/Clipboard_(computing)#X_Window_System).



Actual results:

execCommand('Paste') or clipboard.readText() get the contents of the desktop environment's clipboard and there is no way to retrieve the X selection


Expected results:

In the XPCOM era it was possible to get the contents of the X selection:

        var clip = Components.classes['@mozilla.org/widget/clipboard;1']
            .getService(Components.interfaces.nsIClipboard);
        if (!clip) return null;

        var trans = Components.classes['@mozilla.org/widget/transferable;1']
            .createInstance(Components.interfaces.nsITransferable);
        if (!trans) return null;

        if (typeof(trans.init) === 'function')
            trans.init(null);

        trans.addDataFlavor("text/unicode");
//
// Here we can request the X selection
//
        clip.getData(trans,
                clip.supportsSelectionClipboard()
                ? clip.kSelectionClipboard
                : clip.kGlobalClipboard
        );

Please extend the clipboard API with access to the X selection.
Component: General → DOM
Product: WebExtensions → Core
Nika, any thoughts on this?
Flags: needinfo?(nika)
Exposing this on the web would require an extension to the clipboard standard https://w3c.github.io/clipboard-apis/. There is no mechanism to select which selection to read from in that mechanism. Currently we avoid specialized APIs for webextensions when possible, so there's no obvious place to add a webextension-only capability. Currently the standard expects a single clipboard.
Flags: needinfo?(nika)
Priority: -- → P3
Component: DOM → DOM: Core & HTML
Type: defect → enhancement
Blocks: 1619251
Priority: P3 → P5

Moving this back to WebExtensions as this is not part of the standard and I suspect it will not be standardized as it is highly platform-specific.

Component: DOM: Core & HTML → Untriaged
Product: Core → WebExtensions
No longer blocks: 1619251

The Bugbug bot thinks this bug should belong to the 'Core::XPCOM' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → XPCOM
Product: WebExtensions → Core
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.