I face the same issue. In my case, I use IFrame
s to display diagrams, so document reference, which GoJS uses is not correct, I give a HTMLDivElement
to the constructor, like the author of this topic did, but GoJS raises the same error, even though diagram works perfectly fine in a local-window.
The problem ultimately lays with a check for node instanceof HTMLDivElement
in the GoJS source code, in the go.GraphObject.make
and few other functions (I found at least 3 of these checks in the newest version). The library is not aware in which context it is being used and what DOM node is given to it.
As described in this stackoverflow answer in javascript, how do you determine the type of an dom object, for example, HTMLLIElement or HTMLElement - Stack Overflow and also in javascript - Check if element is a div - Stack Overflow answer comments, instanceof
might give unexpected result if it is called from a different scope. In my case I initialize go.Diagram
from a main window, but the DOM, in which diagram is created - in an IFrame
. So at the end node instanceof HTMLDivElement
just always gives false
and because of it, then the function tries to read parameter as an object
, which then leads to trying to read align attribute on the HTMLDivElement
node HTMLDivElement - Web APIs | MDN and assigning it to the Diagram
object.
To prevent instanceof
giving false assumptions, I would suggest to change this check to an alternative, which would not be influenced by the window
context being something else than expected.
There are at least 3 different alternatives:
div instanceof HTMLDivElement
1. div.toString() === '[object HTMLDivElement]'
2. div.tagName === "DIV"
3. div.nodeName === "DIV"
I’ve in a hacky way replaced instanceof
comparison in GoJs source with the first alternative, to check if that would solve the issue, and it did, no errors were raised from GoJS library. Everything was working as expected. Obviously, I wouldn’t like to do hacking (because of obvious reasons) and I would like, that GoJS support this kind of scenario. The recommended way I guess would be to use tagName
. Would this be possible to change?
I’m attaching a fiddle in which error can be seen (open up dev tools console): Edit fiddle - JSFiddle - Code Playground