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

Should setData(data) only support POST request #6

Closed
mingyc opened this issue Jul 5, 2022 · 7 comments · Fixed by #16
Closed

Should setData(data) only support POST request #6

mingyc opened this issue Jul 5, 2022 · 7 comments · Fixed by #16
Labels
api Issue with API specs question Further information is requested

Comments

@mingyc
Copy link
Collaborator

mingyc commented Jul 5, 2022

setData(data): Set the current beacon data. The data argument would take the same types as the sendBeacon method’s data parameter. That is, one of ArrayBuffer, ArrayBufferView, Blob, string, FormData, or URLSearchParams.

The current proposal doesn't differentiate between GET/POST for the beacon data. But most of them just don't make sense for GET request in term of url encoding, e.g. Blob, ArrayBuffer, ArrayBufferView, and FormData can contain arbitrary bytes which is difficult to encode in url.

Would it make sense to specify beacon data from setData(data) only works for POST?

@yutakahirano
Copy link

+1. Setting data to GET requests sounds strange to me. Ignoring setData calls or even throwing when the method is GET makes sense to me.

@mingyc mingyc added api Issue with API specs discussion question Further information is requested and removed discussion labels Jul 6, 2022
aarongable pushed a commit to chromium/chromium that referenced this issue Jul 12, 2022
Also make the method not support GET request per [discussion][1].

[1]: WICG/pending-beacon#6

Bug: 1293679
Change-Id: Ic5d0993c9bf0fe5c69348bb17b2072b92eded5bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3748752
Reviewed-by: Rakina Zata Amni <[email protected]>
Commit-Queue: Ming-Ying Chung <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Yutaka Hirano <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1023127}
@fergald
Copy link
Collaborator

fergald commented Jul 19, 2022

@yutakahirano You're suggesting that for a GET beacon, you would set the URL only and if you want to update the beacon you don't call setData, you create a new beacon with a new URL? Or maybe the URL is updateable on GET beacon but there is no setData.

@mingyc
Copy link
Collaborator Author

mingyc commented Jul 20, 2022

There was another discussion about atomic property updating in #8 where we decided to make url immutable. We might want to add a new method for updating url for GET beacon?

@fergald
Copy link
Collaborator

fergald commented Jul 20, 2022

Yeah, so actually we might want to have 2 different beacons then, one for GET which can update URL and has no setData.

@mingyc mingyc changed the title Should setData(data) only support POST request Should setData(data) only support POST request Jul 20, 2022
@yutakahirano
Copy link

Encoding arbitrary data into a URL query is not at all trivial, so I think setData is not the right interface for setting URL query. Moreover, if setData can be used to set the URL query for a GET beacon, why can't we do that for a POST beacon?

Hence I think it's good to have a separate function for setting the request content and setting the request URL query (if necessary - is there a use case for this?). For example:

  • setData(data): Set data to the beacon request content. This throws if the method is "GET" or "HEAD".
  • setQuery(params): Set params to the request URL query. params is a URLSearchParams.

@jdfreder
Copy link
Contributor

One particularly nice thing about @fergald's suggestion is that the API is explicit, as opposed to restricting calls based on runtime configuration (HTTP method) which is a potential landmine (runtime Error) for anyone who doesn't read the spec closely.

@fergald
Copy link
Collaborator

fergald commented Jul 21, 2022

@jdfreder yes, for typescript users having 2 separate beacon classes for GET and POST turns a run-time error into a compile-time error.

@yutakahirano
I hadn't thought about HEAD as a method here. Given that the response is never made available, GET and HEAD seem identical (to the page) but I suppose someone might want us to make one or the other in the request. So I guess we should facilitate both but it seems like they would have exactly the same observable behaviour.

Allowing setUrl not just seqQuery seems more flexible and I don't see a downside.

I was rather surprised to find that there are frameworks out there that use different encodings. For example, some params in Chromium Code Search URLs are ;-separated. E.g. l, drc below

https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/render_frame_host_impl.h;l=324;drc=af55b5b6ebe03da36d40e71bd733617291c6c9c7

I complained about it once and was told that it comes from the framework they built it on. So we cannot assume that setQuery(query: SearchURLParams) will actually be OK for everyone.

mingyc added a commit to mingyc/pending-beacon that referenced this issue Jul 27, 2022
- Fix WICG#13: Replace `pageHideTimeout` with `backgroundTimeout` and
  `timeout`. Allow to set them in constructor & data/url setters.
- Address WICG#14: Rename `isPending` to `pending` and specify its
  behaviors.
- Address WICG#14: Keep the low-level sync API, and mark it as chosen.
- Fix WICG#6: Add `PendingGETBeacon` and `PendingPOSTBeacon`.
@mingyc mingyc closed this as completed in 57bdb38 Aug 1, 2022
@mingyc mingyc closed this as completed in #16 Aug 1, 2022
mingyc added a commit to mingyc/pending-beacon that referenced this issue Aug 2, 2022
- Fix WICG#6: Renamed `PendingPOSTBeacon` with `PendingPostBeacon`, and same
  for `PendingGetBeacon`, as it looks like [TAG Design Principles][1] only
  suggests Initialisms for abbreviations, and POST/GET are not abbrs.
- Fix WICG#17
  - Make `PendingPostBeacon` only be queud and its data is non `null`
    and non `undefined`

[1]: https://www.w3.org/TR/design-principles/#casing-rules
mingyc added a commit that referenced this issue Aug 5, 2022
* Update explainer to address API discussions

- Fix #6: Renamed `PendingPOSTBeacon` with `PendingPostBeacon`, and same
  for `PendingGetBeacon`, as it looks like [TAG Design Principles][1] only
  suggests Initialisms for abbreviations, and POST/GET are not abbrs.
- Fix #17
  - Make `PendingPostBeacon` only be queud and its data is non `null`
    and non `undefined`

[1]: https://www.w3.org/TR/design-principles/#casing-rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue with API specs question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants