Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich text copy not working for Google Docs #10

Open
gwicke opened this issue May 11, 2020 · 5 comments
Open

Rich text copy not working for Google Docs #10

gwicke opened this issue May 11, 2020 · 5 comments

Comments

@gwicke
Copy link

gwicke commented May 11, 2020

Short description

Copying the rich text linked title does not work for fully loaded Google Docs tabs, but does work for unloaded ones, and other websites. Other formats (such as separate title & link) work as well.

Steps to reproduce

  1. Start Firefox with clean profile.
  2. Install copy-selected-tabs-to-clipboard
  3. Add a Rich Text (%RT%) option, grant the "use page contents" permission.
  4. Right click on a fully loaded Google Docs tab, and copy as Rich Text.
  5. Paste link into anything accepting rich text content (ex: Google Docs)

Expected result

Tab title is copied as linked, rich text.

Actual result

Clipboard was not updated, previous clipboard content is inserted.

Environment

  • Platform (OS): Fedora 30
  • Version of Firefox: 76
  • Version (or revision) of Multiple Tab Handler: 1.2.3
@piroor
Copy link
Owner

piroor commented Jun 2, 2020

I've tried this with the latest development build but couldn't reproduce it. Could you try it via about:debugging?:
https://piro.sakura.ne.jp/xul/xpi/nightly/copy-selected-tabs-to-clipboard.xpi

Steps I did:

  1. Start Nightly 79.0a1 on Windows 10.
  2. Load the latest development version of this addon via about:debugging.
  3. Prepare two formats and grant the required permission:
    • HTML Link: %RT%<a title="%TITLE_HTML%" href="%URL_HTML%">%TITLE_HTML%</a>
    • Rich text link: %RT%
  4. Go to Google Docs.
  5. Create a blank new document.
  6. Select all tabs and copy as "HTML Link".
  7. Paste the clipboard contents to the document created at 5.
  8. Select all tabs and copy as "Rich text link".
  9. Paste the clipboard contents to the document created at 5.

On both steps 7 and 9 I successfully got inserted links. If you still fail, I think it may be a problem of Firefox or the platform itself...

@piroor piroor added the help wanted Extra attention is needed label Jun 2, 2020
@gwicke
Copy link
Author

gwicke commented Jun 5, 2020

Retried on Mozilla/5.0 (X11; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0.

Neither the nightly, nor the released version of the extension are copying the %RT% format for Google docs tabs, while other tabs (and other link formats on Google Docs) are working fine.

I stepped through the copy process in the debugger, and the richText HTML string looks correct to me. The execution hits the browser.tabs.executeScript(permittedTabs[0].id path, and tries to inject the event based copy code into the gdocs page, but the clipboard is not updated.

piroor added a commit that referenced this issue Jun 8, 2020
@piroor
Copy link
Owner

piroor commented Jun 8, 2020

OK I got it why the difference between my result and your result happens. On my case I select multiple tabs including both Google Docs and other services, and the first tab of them is not Google Docs. On the other hand your case looks to have Google Docs as the first tab.

Due to some technical reasons, this addon executes document.execCommand() and handles it with its own custom event listener, in the first tab of the selection. If you have something another webpage as the first selected tab, the operation succeeds. On the other hand, if the first tab shows Google Docs, document.execCommand() is executed but the event never been handled by the custom event listener. It possibly that such events have been handled and canceled by scripts of the Google Docs service itself.

There is only one workaround: enabling the native clipboard write API of Firefox itself. Go to about:config and turn dom.events.asyncClipboard.dataTransfer to true, then the API becomes available and this addon will use it to copy rich text data without script execution in webpages. (But I've found that there is a mistake and you need to wait a next release including the commit fc80555.)

@piroor piroor removed the help wanted Extra attention is needed label Jun 8, 2020
@piroor
Copy link
Owner

piroor commented Jun 8, 2020

I've released the version 1.3.0 with the fix.

@gwicke
Copy link
Author

gwicke commented Jun 8, 2020

Confirmed that rich text copying is now working for gdocs tabs as well with the preference set. Thank you!

One small nit: When the preference is missing, I am getting the HTML string in the clipboard (with <a> tags), rather than the plain text format. Might be nicer to fall back to the user configured plain text format instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants