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

Can't copy link for SVG and PDF #440

Closed
hacdias opened this issue Apr 4, 2018 · 2 comments
Closed

Can't copy link for SVG and PDF #440

hacdias opened this issue Apr 4, 2018 · 2 comments
Assignees
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@hacdias
Copy link
Member

hacdias commented Apr 4, 2018

On:

http://127.0.0.1:8080/ipfs/QmY9pfuxeojUKSKwLxuQimvwBGrNx9Vg8Jhb97kZwn2tXP/icons/glyph_small_cancel.svg

Copying the Canonical or Public Gateway Link doesn't work. It triggers the notification, but the clipboard remains unchanged.

@lidel lidel added kind/bug A bug in existing code (including security flaws) UX labels Apr 4, 2018
@lidel lidel self-assigned this Apr 4, 2018
@lidel
Copy link
Member

lidel commented Apr 4, 2018

Thank you for finding this gem!

I was able to identify the origin of the bug and it is quite entertaining:

  • due to 'security constraints' of WebExttension API we are unable to copy text to clipboard from the code in the background page
  • as a workaround for 'security constraints', we inject copied text wrapped in a thin script that does the actual copying in the active tab – a real piece of art 🙃
  • this works for regular websites and images (because browser renders images in special case of webpage)
  • SVG seems to be rendered directly, without a HTML wrapper, which results in Error: document.execCommand is not a function

Potential fixes (too late for me, so just doing a brain dump):

  • revisit the code responsible for copying – perhaps APIs improved since 2017
  • introduce fallback for worst case scenarios like this: detect error caused by the lack of document.execCommand and fallback to opening new ephemeral tab with empty HTML page, inject and execute copying code there, then close the tab

@lidel lidel added the status/ready Ready to be worked label Sep 22, 2018
@lidel
Copy link
Member

lidel commented Nov 13, 2018

Unfortunately we still don't have proper API for copying from background page in webextension, it seems:

Same issue with copying happens for PDFs:

Update: Firefox 63 shipped with Clipboard API, worth checking if we can switch to that.

@lidel lidel changed the title Can't copy Canonical nor Public Gateway Link for specific path Can't copy link for SVG and PDF Nov 13, 2018
@lidel lidel closed this as completed in f707f44 Jan 7, 2019
lidel added a commit that referenced this issue Jan 7, 2019
> Context: #440 (comment)

This commit removes the need for content script in Firefox by switching
to modern Clipboard API that landed in Firefox 63.

As a result, we were able to switch copying in Chrome back to the
background page, which fixed copying URLs for SVG and PDF in both
browsers.
@ghost ghost removed the status/ready Ready to be worked label Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants