0

I am wondering if there is any benefit using url over text on the Web Share API?

Let me explain why I am asking this:

I am using the Web Share API to share a URL to my website accompanied with some text like this:

navigator.share({
  title: 'Foobar',
  text: 'Foo foo bar bar!',
  url: 'https://example.com'
})

It works perfectly fine. Except for some long existing bug on iOS Safari that prevents the URL specified in the options.url from being pasteable in for example an input or textarea element. Which renders its functionality partially useless.

Now, a workaround would be to just put the link in the options.text like this instead:

navigator.share({
  title: 'Foobar',
  text: 'Foo foo bar bar! https://example.com',
})

So there's that. But I couldn't find any information on the possible drawbacks this workaround might have.

Tafel
  • 1,017
  • 10
  • 17

1 Answers1

0

It's very much up to the user agent (i.e., the browser) and the receiving app to decide what it makes with the shared data.

Possible values are:

  • url: A string representing a URL to be shared.
  • text: A string representing text to be shared.
  • title: A string representing a title to be shared. May be ignored by the target.

Note the bold part. If your favorite app (in the sense of: the app that you expect the majority of your users to share to) behaves in an undesired way, try changing the way you populate the different fields.

DenverCoder9
  • 2,024
  • 11
  • 32
  • Yeah, this is what I got as well. But apparently the `url` can be ignored as well. But that doesn't answer my actual question: what _might_ be the benefit of using `url` over `text`. And what could be possible drawbacks to just put your url inside the `text` option. – Tafel Oct 06 '22 at 08:15
  • As I said, this may greatly depend on the app. Most apps are very forgiving and just concatenate everything together, as, for example, in a tweet on Twitter. There _may_ be apps that strictly expect things in `url` to be actual URLs, but the spec only [requires](https://w3c.github.io/web-share/#sharedata-dictionary) the `url` field to be a [`USVString`](https://webidl.spec.whatwg.org/#idl-USVString). – DenverCoder9 Oct 07 '22 at 09:13