copy-selected-tabs-to-clipboard icon indicating copy to clipboard operation
copy-selected-tabs-to-clipboard copied to clipboard

CSTTC broken after recent Firefox updates (possible fix included)

Open Decimation opened this issue 1 year ago • 0 comments
trafficstars

Environment

Browser Firefox Nightly 123.0a1 (2023-12-28) (64-bit)
CSTTC version 1.6.2
CSTTC config [email protected](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:

  • I tried using CSTTC %RT% in a different Firefox installation: Firefox 116, which works. However, after updating to 122.0b3, the issue is present. This leads me to believe there were changes made after 116 which either broke or removed API features CSTTC used.

  • The tab generated by CSTTC for copying the %RT% content no longer opens as it used to, which seems to be causing the problem.

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");
...

Decimation avatar Dec 28 '23 21:12 Decimation