I had a number of users report problems with my Better Facebook! Firefox Add-on. The error was always with JSON.parse(), and it only happened with the Add-on, not the Greasemonkey version of the script. I was stumped for over a month. Couldn’t figure it out.
Finally, I found the root cause and solution.
The problem was unicode strings being passed into JSON.stringify(). This sometimes resulted in an invalid JSON structure, which then failed when passed to JSON.parse(). The root cause was not within my code, but within the Greasemonkey User Script Compiler that I used to create the Add-on.
The problem was that the script was not being read in using UTF-8, so when executed it didn’t properly handle UTF-8. In the script-compiler.js file, line 22 (for me) I found this:
var channel=ioService.newChannel(aUrl, null, null);
I simply had to change the line to this instead:
var channel=ioService.newChannel(aUrl, "UTF-8", null);
I re-packaged the add-on and the problem disappeared! Hopefully it anyone else runs into this, a quick Google search will find this page. In all my searching, I hadn’t come across anyone else talking about this specific issue. But solving a very needle-in-a-haystack problem is very rewarding, and I’ll be glad to stop getting error reports!