A real-world use case for making such requests is fetching post titles to help chat users use Markdown-formatted links in messages (and avoiding one-boxing — which is considered bad etiquette by many rooms at least on Stack Overflow — to get meaningful titles) without resorting to using the API for each and every post.
It does not have to be the overly permissive (and opening a whole can of worms) "allow-all header":
Access-Control-Allow-Origin: *
It would be of great help to userscript authors that need their scripts to make cross-origin requests at least between sites of the Stack Exchange network. For example, currently, it is impossible to make a request to *.stackapps.com
from *.stackoverflow.com
because the access control header is not set on responses.
I realize that since Access-Control-Allow-Origin
(see spec) can only allow one origin (unless the value is the wildcard), it will require the backend to maintain a list of allowed Origin
(see MDN) request headers and echo it if the latter is in the list, so the request is just to reconsider the decision made more than 7 years ago.
Userscripts have the userscript APIs, specifically GM_xmlhttpRequest and GM.xmlHttpRequest, which allow making cross-origin requests – Makyen 2 hours ago
While this is indeed possible, usage of GM_*
functions makes userscripts dependent on being run via the manager (whereas with either fetch
or XMLHttpRequest
the script does not depend on one), as well as incurs maintenance cost (for example, not as popular as it used to be but still used Greasemonkey has an asynchronous API and exposes the functions as methods on a global GM
object instead).