Closed itbencn closed 8 months ago
Thanks for reporting. Can you create a minimal demo with an iframe showing how this goes wrong?
It looks like the content is stringified calling .toString()
on a JavaScript object returns "[object Object]"
Thanks for reporting. Can you create a minimal demo with an iframe showing how this goes wrong?
It looks like the content is stringified calling
.toString()
on a JavaScript object returns"[object Object]"
usage: access parent.html
as local server running
The vscode
plugin I am using: Live Preview
or Live Server
Thanks for the demo code, I can indeed reproduce your issue. The cause here is that a JavaScript object created in the main thread is to be used in an iframe. That is a different JavaScript realm. The editor checks whether the input is an Object by checking value.constructor === Object
, but that is false when the value is created in a different JavaScript realm. I'll make the function less strict to fix this issue.
As a workaround, you can do:
const setJson = function (json) {
const jsonCreatedInIframe = JSON.parse(JSON.stringify(json))
const content = {
text: undefined,
json: jsonCreatedInIframe
}
editor.set(content);
}
When I directly call the
setJson
method on the current page to passjson
parameters, thetree view
can expand and display normally. But when I calledsetJson
on the parent page by obtaining the window object, thetext view
was normal, and thetree view
only displayed[object object]
without automatic expansion or even manual expansion.But if I call
setJson
on the parent page and pass thetext
parameter, the tree can expand and display normally