lslezak / monkey_scripts

Set of scripts for the Tampermonkey (https://tampermonkey.net/) plugin
GNU General Public License v3.0
7 stars 3 forks source link

Fix bugzilla trello integration #4

Closed dgdavid closed 3 years ago

dgdavid commented 3 years ago

Recent versions of Firefox browser do not honor the xhr.responseText property, which is being parsed in advance using the given xhr.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:

dgdavid commented 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.

dgdavid commented 3 years ago

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.

dgdavid commented 3 years ago

So, probably Webkit is keeping the responseText property as string but Firefox is not.

Confirmed

Chrome Firefox
Screenshot from 2021-03-10 13-04-53 Screenshot from 2021-03-10 13-03-25
dgdavid commented 3 years ago

@lslezak I see two options

I vote for the first one, what do you think?

lslezak commented 3 years ago

Yes, the first solution is better.