Skip to content

InsertInlinePictureFromBase64("base64Image, "replace") 2x, causes RichApi Error #6573

@A-Glazer

Description

@A-Glazer

When inserting 2 images using context.document.getSelection()[InsertInlinePictureFromBase64](base64Image, "Replace"), the first image places properly but the 2nd image places together with an error message Uncaught (in promise) RichApi.Error: Cannot read properties of null (reading 'runIndex'). This is because there is no selection but getSelection() still thinks there is a selection.

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: Office on the Web (Windows and Mac)
  • Host [Excel, Word, PowerPoint, etc.]: Word
  • Operating System: Microsoft 365
  • Browser (if using Office on the web): Chrome

Expected behavior

Since no image is selected, getSelection() should return without a selection and no error message should appear.

Current behavior

The first image replaces properly, but any subsequent image fails with an error message (and also places). This is because getSelection() is returning with a selection even when there is no selection.

Steps to reproduce

  1. Select an image from the Word web document
  2. Replace the image using
Word.run(async (context) => {
    const selection = context.document.getSelection();
    selection.insertInlinePictureFromBase64(base64Image, "Replace");
    await context.sync();
  });
  1. Don't change your cursor or selection and place another image.
  2. The image will place but an error message appears.

Note: I would think that the 2nd image wouldn't be within a selection, but context.document.getSelection() is returning with a selection.

Link to live example(s)

Screen.Recording.2026-03-11.at.8.48.19.AM.mov

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions