Taskpane Word Add-Ins (office-js) - The Search function return empty object {} in Word 365 online

Viewed 23

I have created a Taskpane Word Add-Ins, written in React Typescript. This sideload add-in is going to search a list of words in Word document and replace them by new words. All functionality works well in desktop MS Word and find all the words. When I upload manifest to Word 365 online, Taskpane loads and looks find but when I click on button to search, then nothing find. The result of search function is always empty object {} Below you can see my code for searching part that will trigger when user click on search button. It is working on desktop version but is not working in Word 365 online

(async () => {
        try {
          let options = Word.SearchOptions.newObject(context);
          options.matchCase = false;
          options.matchWholeWord = true;
          options.ignorePunct = true;
          
          await Promise.all(
            WordList.map(async (data: customWord) => {

            // NOTE: In Word 365 online, searchResults is always {} 
              const searchResults = textSelected
                ? context.document.getSelection().search(data.word, options)
                : context.document.body.search(data.word, options);

              searchResults.load("items, text");
              allSearchResults.push(searchResults);
            })
          );
        } catch (error) {
          console.error(error);
        }
    })();

Does anyone know why search result is empty in Word Online? Is it related to code Promise.all() when running via browser?

0 Answers
Related