Open lucaswerkmeister opened 4 months ago
Thanks Lucas!
I tried to add this (like the fetch code in https://foundation.wikimedia.org/wiki/Policy:User-Agent_policy):
fetch('https://query.wikidata.org/sparql?query=' + encodedQuery, { method: 'GET', headers: new Header( { 'Accept': 'application/json', 'Api-User-Agent': 'Entity-Explosion (https://www.wikidata.org/wiki/Wikidata:Entity_Explosion)' } ) }) .then(
But I got this error: Access to fetch at 'https://query.wikidata.org/sparql?query='xxx' from origin 'chrome-extension://lkehkcgnfbfapdachbalabbhfkngbbem' has been blocked by CORS policy: Request header field api-user-agent is not allowed by Access-Control-Allow-Headers in preflight response.
A fairly old stack overflow suggests that the issue is at the other end and I should remove the user agent!? https://stackoverflow.com/questions/51575656/how-to-properly-cors-fetch-from-the-wikipedia-api
Any help would be appreciated, because I'm at a roadblock for now. @lucaswerkmeister
Hm, I didn’t realize query.wikidata.org didn’t allow Api-User-Agent
. (Or, apparently, User-Agent
.) Filed as T362570 now; in the meantime, I guess you can just leave out the header.
Thanks for filing. I didn't realise this was unexplored territory!
Me neither :D
Do you also use the Wikidata API (/w/api.php
, or /w/rest.php
I suppose) anywhere, or only SPARQL/WDQS? If you use the normal API, you could at least add the user agent there…
You're right, I've just turned that one back on in my development version. It is only used when the user invokes the extension from a Wikimedia site, and it just calls for the wikibase item QID, so I can't imagine it causing much load compared to the Wikidata queries.
User agent headers should be supported now: https://phabricator.wikimedia.org/T362570#9932326
BTW, neat extension!
Entity Explosion should set a user agent header with its requests (the
fetch()
calls initem-properties.js
andbackground.js
), identifying itself according to the user agent policy.According to the web standards, you should be able to specify a custom
User-Agent
in requests (it is no longer a forbidden header name), and in Firefox this is indeed supported. However, Chrome/Chromium ignores the standard and continues to drop this header. Instead, you can sendApi-User-Agent
, which has no restrictions; it’s probably easiest to just do this in all the versions of the extension (rather than making the Firefox version sendUser-Agent
and the Chrome versionApi-User-Agent
).Example: