insertFileFromBase64: "The action is not supported by word in a browser."

Rahul Kumar 0 Reputation points
2025-12-11T08:00:32.44+00:00

In word online the following Office js API is throwing error "The action is not supported by word in a browser." The same code works fine in the word desktop. Could you please let me know if there is any alternative to this API which will work in both word online and desktop version?

The requirement is to replace the modified content of the currently opened word document with the original content stored in the "originalBase64" string.

Office Js API: document.body.insertFileFromBase64(originalBase64, Word.InsertLocation.replace)

Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michelle-N 9,240 Reputation points Microsoft External Staff Moderator
    2025-12-11T10:19:06.1833333+00:00

    Hi @Rahul Kumar

    Thank you for posting your question in the Microsoft Q&A forum. 

    Based on the information you described, I understand that your code using document.body.insertFileFromBase64 with Word.InsertLocation.replace works perfectly on Word Desktop but fails on Word Online with the error: "The action is not supported by word in a browser." You are looking for an alternative that works consistently across both platforms to replace the document content.

    This issue typically arises due to feature parity differences between the host clients. While Word Desktop handles complex file insertion actions well, the browser version often reports errors or hangs when processing specific InsertFileOptions, especially regarding pagination and section breaks.

    Based on my research, there is currently no single direct API that acts as a perfect drop-in replacement for insertFileFromBase64 that works flawlessly for full body replacement on Word Online without modification. However, I recommend the following two approaches:

    Before rewriting your logic, try modifying the options passed to the API. Some users suggest that certain flags cause the browser version to crash or throw errors.

    • If you are currently using importDifferentOddEvenPages: true in your options, remove it.
    • Try reducing the options object to the bare minimum.
    • Ensure you are targeting context.document.body correctly.

    If the direct file insertion continues to fail, the most reliable cross-platform alternative is to convert your Base64 .docx file into a Flat Office Open XML (Flat OPC) string and use the insertOoxml API. This API is generally more stable on Word Online for content replacement.

    Instead of inserting the binary .docx file, you parse the file structure and insert the raw XML content. You will need to include the JSZip library in your add-in project to unzip the .docx Base64 data. Then, use JavaScript to unzip the Base64 content and construct a Flat OPC XML string.

    Like your original API call, this replaces the body content. If you need to replace headers, footers, or section properties, insertOoxml on the body might not automatically overwrite existing section properties on the web. You may need to explicitly clear them first by iterating through context.document.sections and calling methods like section.getHeader(...).clear() or section.body.clear() before inserting the new XML.

    Note: For very large documents, monitor performance, as constructing the Flat OPC string requires processing the file in the browser.

    Please try Option 1 first, and if the issue persists, proceed with the Flat OPC conversion in Option 2. Let me know if you need further assistance with the code!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.