Chrome sendrequest error: TypeError: Converting circular structure to JSON(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
However, my code never reaches "ZOMG HERE" but rather throws the following error while running chrome.extension.sendRequest
Uncaught TypeError: Converting circular structure to JSON
chromeHidden.JSON.stringify
chrome.Port.postMessage
chrome.initExtension.chrome.extension.sendRequest
suggestQuery
有人知道是什么原因造成的吗?
Does anyone have any idea what is causing this?
推荐答案
表示你在请求中传入的对象(我猜是pagedoc)有循环引用,类似于:
It means that the object you pass in the request (I guess it is pagedoc) has a circular reference, something like:
var a = {};
a.b = a;
JSON.stringify 不能像这样转换结构.
JSON.stringify cannot convert structures like this.
注意:DOM 节点就是这种情况,它们具有循环引用,即使它们没有附加到 DOM 树.每个节点都有一个 ownerDocument,它在大多数情况下引用 document.document 至少通过 document.body 引用 DOM 树,而 document.body.ownerDocument 引用回 document 再次,这只是 DOM 树中多个循环引用中的 一个.
N.B.: This would be the case with DOM nodes, which have circular references, even if they are not attached to the DOM tree. Each node has an ownerDocument which refers to document in most cases. document has a reference to the DOM tree at least through document.body and document.body.ownerDocument refers back to document again, which is only one of multiple circular references in the DOM tree.
这篇关于Chrome sendrequest 错误:TypeError:将循环结构转换为 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Chrome sendrequest 错误:TypeError:将循环结构转换为 JSON
基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
