goatslacker/alt-devtool

Debugger causes alt to crap out when JSON.stringify fails

rocketraman opened this issue · 5 comments

I have a data structure being passed through the dispatcher that contains circular references (third party library, don't ask). When the chrome debugger is enabled a call to JSON.stringify, the following error is raised and alt fails to dispatch the event:

TypeError: Converting circular structure to JSON

The code in which it fails is:

function registerAlt() {
  ....
  listeners = alts.map(function (obj, i) {
    ....
    var listener = finalStore.listen(function (_ref) {
      ...
      post("DISPATCH", {
        alt: i,
        id: id,
        action: payload.details.id,
        data: JSON.stringify(payload.data)     // <----- fails here
      });

So I think there are two problems:

  1. The Chrome debugger hook should probably just log any failures but allow the dispatch to continue.

  2. The stringify should handle circular refs. See this stack question for a way to do that: http://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json

I've hit the same issue once or twice. I'm inclined to agree with 1), because I don't think it's in any way mandatory to get the payload into the devtool. It's NICE of course but no need to halt the app.

@goatslacker Can you compile the crx with this fix? Or describe a away to create crx from sources?

This would be nice! I've just manually patched this in to the extension source, and then promptly forgot about it. Which means it'll break whenever I reinstall for some reason...

👍 I'll amend with @jareware's patch

Patched and released.