I am currently developing an add-in that utilises text to speech to speak each sentence within the document. I use tracked objects to track the sentences as they need to be spoken one after another.
The issue arises when trying to change the font colour of the sentence (highlight whilst being spoken) by loading and accessing the 'font.color' property. This will work on Desktop, but will throw the following error Online:
Debug info: {"code":"GeneralException","message":"Cannot read property 'gO' of null","errorLocation":"Range._onAccess"}
Below is the minimum code to reproduce the issue:
...
var sentences;
...
Word.run(function (context) {
var selectedSentence = context.document.getSelection().getTextRanges([".", "!", "?"]);
context.load(selectedSentence)
return context.sync().then(function () {
sentences = selectedSentence.items[0].getRange()
.expandTo(context.document.body.paragraphs.getLast().getRange("end"))
.getTextRanges([".", "!", "?"]);
context.load(sentences);
context.trackedObjects.add(sentences);
return context.sync(sentences);
})
}).then(function (sentences) {
sentences.context.load(sentences, 'font');
return sentences.context.sync().then(function () {
sentences.items[0].font.color = "#2E86C1";
})
.then(sentences.context.sync)
}).catch(errorHandler);
The error will also be produced if you simply try to access it directly:
sentences.items[0].font.color = "#2E86C1";
sentences.context.sync();