piroor / copy-selected-tabs-to-clipboard

Provides ability to copy title and URL of selected tabs to the clipboard for Firefox 63 and later.
Other
84 stars 16 forks source link

CSTTC broken after recent Firefox updates (possible fix included) #51

Closed Decimation closed 7 months ago

Decimation commented 11 months ago

Environment

Browser Firefox Nightly 123.0a1 (2023-12-28) (64-bit)
CSTTC version 1.6.2
CSTTC config configs-copy-selected-tabs-to-clipboard@piro.sakura.ne.jp(1).json

Short description

I have been using CSTTC without issue until recently, where I found that using %RT% format throws an exception:

14:34:07.506 clipboard<BG>:       failed to write text/data to clipboard:  TypeError: Clipboard.write: Argument 1 can't be converted to a sequence.
    copyToClipboard moz-extension://6ebf3598-f26a-4036-8a43-851309901bab/common/commands.js:92
    onClick moz-extension://6ebf3598-f26a-4036-8a43-851309901bab/background/context-menu.js:473
common.js:77:11

Affected code: commands.js:92 and context-menu.js:473.

I've been investigating and debugging myself and made a few discoveries:

Steps to reproduce

  1. Use CSTTC on Firefox 116+
  2. Attempt to copy any tab on any website using %RT% format

Possible fix

The following change to commands.js appears to resolve the issue, and the %RT% format works as expected.

...
/* const dt = new DataTransfer();
dt.items.add(plainText, 'text/plain');
dt.items.add(richText, 'text/html'); */

const ci1 = new ClipboardItem({
    ["text/plain"]: plainText,
    ["text/html"]: richText,
});

/* navigator.clipboard
    .write([ci1])
    .then(() => {
        notifyCopied(tabs.length, plainText);
    })
    .catch((error) => {
        notifyFailed(error);
    }); */

await navigator.clipboard.write([ci1]).then(() => {
    notifyCopied(tabs.length, plainText);
});

console.log("Text has been copied to clipboard");
...
piroor commented 7 months ago

I'm very sorry for my long silence. I've merged the PR and refactored changes.