Errors when using domAtPos

I’m getting Uncaught TypeError: Cannot read property ‘docView’ of undefined when i write this: `

const dom = domAtPos(position);

the error is pointing the line with the return statement in the domAtPos function

const { state, dispatch, docView, domAtPos } = view;
EditorView.prototype.domAtPos = function domAtPos (pos, side) {
    if ( side === void 0 ) side = 0;

  return this.docView.domFromPos(pos, side)
};

I have also tried to write

const dom = docView.domFromPos(position);

but the error Uncaught TypeError: Cannot read property ‘contentDOM’ of undefined rises and it’s pointing to the first line of the domFromPos function

ViewDesc.prototype.domFromPos = function domFromPos (pos, side) {
  if (!this.contentDOM) { return {node: this.dom, offset: 0} }
....

domAtPos is a method of the editor view, so why is your example code calling it like a top-level function?

Actually this prosemirror-utils lib requires it as parameter to be passed to some of its functions

I don’t now about prosemirror-utils, but this is a method, and you can’t call it without its object. Maybe you need to bind it or something, when passing it around.

1 Like