In my Nuxt PWA, I have a function that converts HTML to Canvas using this package. The generated image is in base 64. Now I want to be able to share the image via: Whatsapp, Facebook, Email, Instagram, etc. I've found a few packages, but none of them seem to support sharing just file URLs and text.
This is my sharing function:
shareTicket(index) { html2canvas(this.$refs['ticket-' + index][0], { backgroundColor: '#efefef', useCORS: true, // if the contents of screenshots, there are images, there may be a case of cross-domain, add this parameter, the cross-domain file to solve the problem }).then((canvas) => { let url = canvas.toDataURL('image/png') // finally produced image url if (navigator.share) { navigator.share({ title: 'Title to be shared', text: 'Text to be shared', url: this.url, }) } })
When I take out the if (navigator.share)
condition, I get an error in my console saying navigator.share
is not a function. I read somewhere that it only works with HTTPS, so I uploaded to my staging server and tried it, but still got the same error.
To be clear, I want to be able to share the generated image itself, not the URL.
I have a variation of the following code in the
share()
function in my application and it works fine if executed on the client.Tell me if this URL works for you: https://nuxt-share-social- media.netlify.app
If so, you can find the Github repository here: https://github.com/ Kissu/so-share-image-bounty
The code is
Inspired by @denvercoder9!