Chrome sendrequest error: TypeError: Converting circular structure to JSON

后端 未结 11 1032
醉梦人生
醉梦人生 2020-11-22 04:16

I\'ve got the following...

chrome.extension.sendRequest({
  req: \"getDocument\",
  docu: pagedoc,
  name: \'name\'
}, function(response){
  var efjs = respo         


        
11条回答
  •  盖世英雄少女心
    2020-11-22 05:05

    I normally use the circular-json npm package to solve this.

    // Felix Kling's example
    var a = {};
    a.b = a;
    // load circular-json module
    var CircularJSON = require('circular-json');
    console.log(CircularJSON.stringify(a));
    //result
    {"b":"~"}
    

    Note: circular-json has been deprecated, I now use flatted (from the creator of CircularJSON):

    // ESM
    import {parse, stringify} from 'flatted/esm';
    
    // CJS
    const {parse, stringify} = require('flatted/cjs');
    
    const a = [{}];
    a[0].a = a;
    a.push(a);
    
    stringify(a); // [["1","0"],{"a":"0"}]
    

    from: https://www.npmjs.com/package/flatted

提交回复
热议问题