Closed dgdavid closed 3 years ago
Note: the code is using responseType: "json"
which, according to the MDN documentation, makes the response to be
a JavaScript object created by parsing the contents of received data as JSON.
It could explain what is happening, although it does not explain why the issue is not present in Chrome browsers.
https://javascript.info/xmlhttprequest#response-type
In the old scripts you may also find xhr.responseText and even xhr.responseXML properties.
They exist for historical reasons, to get either a string or XML document. Nowadays, we should set the format in xhr.responseType and get xhr.response as demonstrated above.
So, probably Webkit is keeping the responseText
property as string but Firefox is not.
So, probably Webkit is keeping the
responseText
property as string but Firefox is not.
Confirmed
Chrome | Firefox |
---|---|
@lslezak I see two options
response.response
instead of response.responseText
, orJSON.parse(response.responseText)
in a try/catch blockI vote for the first one, what do you think?
Yes, the first solution is better.
Recent versions of Firefox browser do not honor the
xhr.responseText
property, which is being parsed in advance using the givenxhr.responseType
.As agreed in https://github.com/lslezak/monkey_scripts/pull/4#issuecomment-795402632, using
xhr.response
property looks a good solution that should work in both, Firefox and Webkit browsers.Show/hide Firefox complain
```js Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data onload moz-extension://userscripts/Bugzilla Trello integration.user.js:590 s eval:4 i eval line 2 > Function:36 s eval:4 i eval line 2 > Function:13 s eval line 2 > Function:13 v eval:13 v eval:13 s eval:4 t eval:12 s eval:4 h eval:12 h eval:12 send eval:13 s eval line 2 > Function:13 setTimeout eval line 2 > Function:14 i eval line 2 > Function:36 xmlhttpRequest eval line 2 > Function:43 message eval line 2 > Function:19 s eval:4 t eval:3 message eval line 2 > Function:19 message eval line 2 > Function:19 anonymous eval line 2 > Function:77 v eval:13 eval line 4 > eval:590:28 ```Manual tests: