Current code will fallback to this.quill.getLength() when you move your cursor to the beginning of content.
insert(dataUrl) {
const index =
(this.quill.getSelection() || {}).index || this.quill.getLength();
this.quill.insertEmbed(index, 'image', dataUrl, 'user');
}
Check the result of getSelection may be a better solution.
insert(dataUrl) {
const selection = this.quill.getSelection();
const index = selection
? selection.index
: this.quill.getLength();
this.quill.insertEmbed(index, 'image', dataUrl, 'user');
}