Closed Bug 1473780 Opened 6 years ago Closed 6 years ago

Webextension / Add-on / Javascript behaves differently on Linux Firefox than on Mac or Windows Firefox

Categories

(WebExtensions :: Untriaged, defect)

60 Branch
defect
Not set
normal

Tracking

(firefox61 affected, firefox62 affected, firefox63 affected)

RESOLVED INVALID
Tracking Status
firefox61 --- affected
firefox62 --- affected
firefox63 --- affected

People

(Reporter: code, Unassigned)

Details

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

Steps to reproduce:

Add the extension to Firefox (tested with Firefox 60 and 61):
https://addons.mozilla.org/en-US/firefox/addon/copy-all-tabs/?src=api

Or download source and add ff-web_extension directory as a temporary add-on in Firefox:
git clone https://github.com/charlesbrandt/copy_all_tabs

about:debugging

Enable add-on debugging

Open debug window for add-on

Open multiple tabs in a browser window.
Use the browser_action icon to initiate a "Copy Tabs" action.

Open a text editor and paste the resulting list of tabs URLs that was copied.



Actual results:

On Mac and Windows platforms, the text is copied to the clipboard and subsequent paste operations work.

On Linux, nothing happens.
If I comment out the following lines in background.js:

      // setTimeout(() => {
      //   if (done) { return; } done = true;
      //   document.removeEventListener('copy', onCopy);
      //   reject(new Error('Timeout after '+ (time || 1000) +'ms'));
      // }, time || 1000);

I see the following output in the Developer Tools Console:

[Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIMessageSender.sendAsyncMessage]"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: resource://gre/modules/ExtensionUtils.jsm :: sendAsyncMessage :: line 533"  data: no]  (unknown)
	sendAsyncMessage resource://gre/modules/ExtensionUtils.jsm:533:51
	_handleMessage/deferred.promise< resource://gre/modules/MessageChannel.jsm:984:9




Expected results:

I expected the webextension to work the same way as it does on Mac and Windows by copying the tab URLs and titles to the clipboard, making it available for paste in other applications.

More Info:
https://stackoverflow.com/questions/51110591/how-do-i-enable-copy-to-clipboard-in-firefox-on-linux
I will mark this issue as new.

The errors returned On Firefox 61, Ubuntu 16.04 are: 
Async statement execution returned with '1', 'no such table: moz_hosts' nsPlacesExpiration.js:614
Error: Timeout after [object Object]ms background.js

On Nightly 63.0a1 (2018-07-10), the copy seems successful, but when the Paste button is clicked the same error message is shown and no tabs are pasted.

Setting it to Core: Javascript Engine
Status: UNCONFIRMED → NEW
Component: Untriaged → JavaScript Engine
Ever confirmed: true
Product: Firefox → Core
No idea what component this belongs in. Leaving in the JS engine for now.

adw, per the error message in comment 1, could this be something in nsPlacesExpiration.js (or something else misusing it)?
Flags: needinfo?(adw)
Component: JavaScript Engine → Places
Flags: needinfo?(adw)
Product: Core → Toolkit
Er, now that I moved this to Places, I don't think this is actually Places related, so I'll move it back to JS for now.  Sorry for the bugspam.

David, your error is different from the one in comment 0 and as far as I can tell isn't related to the bug.  The error you're seeing is a result of running a profile created in 62 and later in a 61-and-earlier Firefox.  We stopped creating the moz_hosts table starting in 62.  I don't think there's any reason to believe this bug is related to that.
Component: Places → JavaScript Engine
Flags: needinfo?(david.olah)
Product: Toolkit → Core
This issue seems to work fine on the latest Nightly build: 63.0a1 20180821100053 on Ubuntu 16.04, which lead me to assume that there was a fix done somewhere in the m-c. Running a find-fix for this issue led me to:

INFO: First good revision: 4e6486b672b32aba075b704c6b1e41e8ccf7a135
INFO: Last bad revision: a809b45ff49ba5814795b30b5a460d7d2d1b6a23
INFO: Pushlog:
https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=a809b45ff49ba5814795b30b5a460d7d2d1b6a23&tochange=4e6486b672b32aba075b704c6b1e41e8ccf7a135

which contains a set of backouts related to Bug 1478308.

I'm a bit confused of the reliability of the mozregression since the time frames do not actually match, there might also be a scenario in which multiple fixes and breaks were introduced along: the issue is reported as early as Fx60.  

Might be that this a more convoluted issue that at a first glance, hence I am reluctant to change the status flags and component at least until we get more info on it. Mark, could you look a bit into this issue?
Flags: needinfo?(david.olah) → needinfo?(standard8)
Looking into this I think this is invalid or wontfix. From:

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard#Reading_from_the_clipboard

It says that:

"""
You can write to the clipboard like this in all execution contexts except background pages. In Firefox you can't select text or focus an input field in background pages, so you can't write to the clipboard from a background page.
"""

The background file is attempting to do something like:

```
function onCopy(event) {
  const transfer = event.clipboardData;
  transfer.clearData();
  transfer.setData('text/plain', message.content);
}
document.addEventListener('copy', onCopy);
document.execCommand('copy', false, null);
```

Although the reporter isn't using selection here, I suspect that on Linux the focus handling is different enough that attempting any attempt to copy in the background page isn't going to work at all.

I think that it should be moved back into the extension's tab.js file, though I don't know why that would cause security issues on certain pages. This definitely seems like more of a WebExtension issue than a javascript issue, and if there's issues with it in tab.js, I would recommend discussing those with the WebExtension team.
Component: JavaScript Engine → Untriaged
Flags: needinfo?(standard8)
Product: Core → WebExtensions
(In reply to David Olah from comment #1)
> The errors returned On Firefox 61, Ubuntu 16.04 are: 
> Async statement execution returned with '1', 'no such table: moz_hosts'
> nsPlacesExpiration.js:614
> Error: Timeout after [object Object]ms background.js

This could just be symptom of a profile created in a new version and then reused in an old version, in general we support upgrade/downgrade/upgrade, but in some cases it's not possible to downgrade a profile created in a newer version.
Comment 5 seems unrelated to the original report.  The original report appears to be fixed (or a symptom of doing unsupported downgrades).  In either case, there's no bug here that should keep this open.

As for the clipboard and webextensions, comment 5 is too vague to do anything with.  If you've encountering a specific issue using the clipboard from a webextension, please either re-open this bug or file a new bug and explain the issue clearly.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.