프로그래밍 언어/HTML,CSS,JS

Chrome sendrequest 오류 : TypeError : Converting circular structure to JSON

Rateye 2021. 7. 29. 09:51
728x90
반응형

 

질문 : Chrome sendrequest 오류 : TypeError : 원형 구조를 JSON으로 변환

다음이 있습니다 ...

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

누구든지 이것의 원인을 알고 있습니까?

답변

요청에서 전달한 객체 ( pagedoc )에 다음과 같은 순환 참조가 있음을 의미합니다.

var a = {};
a.b = a;

JSON.stringify 는 이와 같은 구조를 변환 할 수 없습니다.

주의 : DOM 트리에 연결되지 않더라도 순환 참조가있는 DOM 노드의 경우입니다. 각 노드에는 대부분의 경우 document 를 참조 ownerDocument document 적어도 통해 DOM 트리에 대한 참조를 갖는다 document.body 하고 document.body.ownerDocument 다시 가리킨다 document DOM 트리에서 복수의 참조 원의 하나 인, 다시.

출처 : https://stackoverflow.com/questions/4816099/chrome-sendrequest-error-typeerror-converting-circular-structure-to-json
728x90
반응형