Topic: Need help to add user-agent(additional information) to userscript.

Posted under e621 Tools and Applications

First of all I am not good at javascript(I am newbie that make script with wiki). For why I used xmlhttpRequest. İ can't attach user-agent via xhr.setRequestHeader(useragent) (don't know why but it not let script work). My userscript var is "e621byYusifx1/0.95 userscript". Should i add _client("e621byYusifx1/0.95 userscript") to url or what. And I will change xhr to GM if I had time.
Ps:it's may language barrier if I can't understand terms and sorry if my english bad.

bitWolfy

Former Staff

I've run into the same problem before.

The proper way to do it is xhr.setRequestHeader("User-Agent","e621byYusifx1/0.95 userscript");, of course. However, as you might have noticed, this throws an error:

Refused to set unsafe header "user-agent"

Funnily enough, it's not supposed to happen, since user-agent is no longer a forbidden header name. Firefox complies with this standard, but Chrome does not.

Thus, as per the the information on the api page, you should set the user-agent like this:

https://e621.net/posts.json?tags=horse&_client=e621byYusifx1%2F0.95%20userscript

Note that the _client parameter value is properly escaped via encodeURIComponent() to avoid issues.

  • 1