When calling insertFileFromBase64 in word online (build 16.0.12719.32656), the following error will be thrown when trying to insert some documents:
Full error object: “RichApi.Error: Cannot read property 'ha' of null at new c (https://appsforoffice.microsoft.com/lib/1/hosted/word-web-16.00.js:24:293287) at b.f.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/1/hosted/word-web-16.00.js:24:353940) at https://appsforoffice.microsoft.com/lib/1/hosted/word-web-16.00.js:24:352045“.
The actual content of the document is inserted, but any subsequent calls to insertFileFromBase64 throw “The action isn’t supported by Word in a browser," and the document content is not inserted.
The same documents can be inserted using the same logic in any word desktop client.
I'm wondering what is different in word online that could cause this error to be thrown, and how it should be handled to prevent future calls from failing to insert document content?
Here is the code I'm using to insert the document:
Word.run(async (context: Word.RequestContext) => {
const sections = context.document.sections;
sections.load();
await context.sync();
sections.items.forEach(function(section) {
// Clear the Body.
section.body.clear();
// Clear any Headers.
section.getHeader('Primary').clear();
section.getHeader('FirstPage').clear();
section.getHeader('EvenPages').clear();
// Clear any Footers.
section.getFooter('Primary').clear();
section.getFooter('FirstPage').clear();
section.getFooter('EvenPages').clear();
});
await context.sync();
context.document.body.insertFileFromBase64(base64EncodedDocument, 'Start');
return context.sync();
}).catch(e => {
console.log(e.message);
});
Here is an example of a document that throws this error when inserted in office online: https://www.dropbox.com/s/k25ppswzxanb7ez/ASP%20clauses%20non%20admin%20test.docx?dl=0
Here is the full e.debugInfo object: e.debugInfo