我有以下内容…
chrome.extension.sendRequest({
req: "getDocument",
docu: pagedoc,
name: 'name'
}, function(response){
var efjs = response.reply;
});
调用下面的..
case "getBrowserForDocumentAttribute":
alert("ZOMG HERE");
sendResponse({
reply: getBrowserForDocumentAttribute(request.docu,request.name)
});
break;
然而,我的代码从未达到“ZOMG HERE”,而是在运行chrome.extension.sendRequest时抛出以下错误
Uncaught TypeError: Converting circular structure to JSON
chromeHidden.JSON.stringify
chrome.Port.postMessage
chrome.initExtension.chrome.extension.sendRequest
suggestQuery
有人知道是什么引起的吗?
你可能做过类似的事情
<Button onClick={fetchSuggestions}>
未能意识到您已将“事件对象”传递给该函数
如果你不想传递任何东西,只需发送一个空字符串
<Button onClick={() => fetchSuggestions()}>
const fetchSuggestions = async (propsSession) => {
const {
error,
hasNextDoc,
suggestions: moreSuggestions,
} = await fetcher(`/admin/fetchSuggestion`, {
initialRequest: !!propsSession,
session: propsSession || session,
});
}
你可能做过类似的事情
<Button onClick={fetchSuggestions}>
未能意识到您已将“事件对象”传递给该函数
如果你不想传递任何东西,只需发送一个空字符串
<Button onClick={() => fetchSuggestions()}>
const fetchSuggestions = async (propsSession) => {
const {
error,
hasNextDoc,
suggestions: moreSuggestions,
} = await fetcher(`/admin/fetchSuggestion`, {
initialRequest: !!propsSession,
session: propsSession || session,
});
}
一种方法是从主对象中剥离对象和函数。并对更简单的形式进行stringalize
function simpleStringify (object){
// stringify an object, avoiding circular structures
// https://stackoverflow.com/a/31557814
var simpleObject = {};
for (var prop in object ){
if (!object.hasOwnProperty(prop)){
continue;
}
if (typeof(object[prop]) == 'object'){
continue;
}
if (typeof(object[prop]) == 'function'){
continue;
}
simpleObject[prop] = object[prop];
}
return JSON.stringify(simpleObject); // returns cleaned up JSON
};
如果你使用node js使用inspect()(参考文档)
import {inspect} from "util";
console.log(inspect(object));