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

navigator.clipboard is undefined #15

Closed
iggant opened this issue Feb 11, 2019 · 7 comments
Closed

navigator.clipboard is undefined #15

iggant opened this issue Feb 11, 2019 · 7 comments

Comments

@iggant
Copy link

iggant commented Feb 11, 2019

Firefox Developer Edition 66.0 Beta 6 (20190207161357)

TypeError: navigator.clipboard is undefined[Learn More] heavens_door.js:31:5

when I type:
sessionStorage.heavensDoor

It always return:

"  scenario 'GENERATED' do
    visit '/whitelabels/clients/new'
"
@amatsuda
Copy link
Owner

It works with Firefox stable release on my machine.
If you're seeing that bug only on the Developer Edition, please try to debug your browser yourself, or report the bug to their bugzilla, or consider using stable software.

@brendanwb
Copy link

I was running into the same issue in multiple browsers (Safari, Chrome, and Firefox). After some research, I found that navigator.clipboard is only available when the site you're browsing has a secure origin (https). I switched my development environment to use https, and this fixed the issue for Firefox and Chrome. According to devdocs, Safari is still implementing support.

@amatsuda
Copy link
Owner

@brendanwb Interesting. Is the situation same on a vanilla Rails app?
If not, you may be setting some kind of secure header on your app, and I suppose you could turn that off on development env.

@brendanwb
Copy link

@amatsuda it shouldn't matter what kind of Rails app, it's dependent on the browser. If you go to any website using https and open the web inspector, navigator.clipboard is available. If you go to any website that doesn't use https, Rails or otherwise, navigator.clipboard won't be available.

@paranishian
Copy link

paranishian commented Dec 10, 2019

I had the same problem, but in my case, it was because I was using lvh.me.

Browser: Chrome 78.0.3904.108(Official Build)

localhost:3000 paranishian.lvh.me
image image
image image

amatsuda added a commit that referenced this issue Dec 16, 2019
…lable

navigator.clipboard is available only on localhost or over secure connection.

closed #15
@amatsuda
Copy link
Owner

@paranishian Thank you very much for a super helpful input!
Yes, the Clipboard API seems to be strictly limited to work only on localhost or over secure connection, and I haven't imagined using this gem outside of such environment.
Since lvh.me is something that I definitely want to support, I just pushed an adhoc patch fce8afc that falls back to good old legacy execCommand("copy") with a temporary dummy element for copying the content (I know this code is a mess, TBH I don't really want to maintain such a crap, but I couldn't come up with a better way doing this. Patches are welcome...).

@amatsuda
Copy link
Owner

Also, just published a new gem package with this change as version 0.3.0.

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

4 participants