w3c / web-share-target

Web API proposal for receiving shared data
https://w3c.github.io/web-share-target/
Other
191 stars 20 forks source link

How to validate a share_target url ? #38

Closed xfalcox closed 6 years ago

xfalcox commented 6 years ago

I can't get my webapp to show as a share target in the current Chrome Canary.

Here is the manifest:

https://meta.discourse.org/manifest.json

mgiuca commented 6 years ago

Hi, it sounds like you have a Chrome issue, not an issue with the web standard. These should be reported to https://crbug.com/new.

Though I wonder if you've installed the app as a WebAPK (requires that it satisfies the PWA Checklist). Chrome for Android only lets installed PWAs register as share targets.

mgiuca commented 6 years ago

Closing the issue. If it is still a problem, please report on https://crbug.com/new.

xfalcox commented 6 years ago

Thanks for the reply @mgiuca!

Though I wonder if you've installed the app as a WebAPK

Yes, I did.

Hi, it sounds like you have a Chrome issue, not an issue with the web standard.

My question would be how to properly encode line breaks and & in the web share url in the manifest.

Using the standard rails json encoder this:

"share_target": {
  "url_template": "new-topic?title={title}&body={text}\n\n{url}"
}

becomes this:

"share_target": {
  "url_template": "new-topic?title={title}\u0026body={text}%0A%0A{url}"
}

Is this a valid manifest, per the spec?

mgiuca commented 6 years ago

I was wondering why you had \u0026 and %0A%0A in there. '\u0026' and '&' are exactly equivalent in JSON so that will be the same. '%0A' and '\n' should be equivalent per the URL standard. So that encoding that Rails is doing is fine, though it shouldn't be necessary.

I'm not sure why you want newlines in your URL. If you're trying to create a POST-style HTTP request body (by inserting two newlines), that won't work. This will just make a GET request with "%0A%0A" in the request header.

I don't see any reason, though, why this wouldn't be accepted as a valid web share target URL.

xfalcox commented 6 years ago

I'm not sure why you want newlines in your URL. If you're trying to create a POST-style HTTP request body (by inserting two newlines), that won't work. This will just make a GET request with "%0A%0A" in the request header.

This is a our URL at Discourse to create a new topic in Discourse:

https://meta.discourse.org/new-topic?title=title&body=text%0A%0Aurl

will produce:

image

I tested a sharing a bunch of stuff from different Android apps, and we don't always get url and text so I'm just adding both to our post text area separated by line breaks to help the user compose his topic.

However it's not being correctly detected by current Chrome Canary in the Android and I was afraid that one of those special characters were infringing the spec.

mgiuca commented 6 years ago

Ahh I see, sorry I completely missed the fact that the URL was part of the "body" parameter (I thought you were trying to do some weird HTTP thing). That makes sense and should work. Can you file a bug in https://crbug.com/new, and I'll try to look at it.

Note: We've recently discussed changing this to a new syntax which would not allow you to compose a parameter like that (you would only be able to set each query parameter to one of the share fields). I've written an analysis of this on a comment on that issue.