OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
685 stars 95 forks source link

insertOoxml always causes exception "word-web-16.00.js:27 Uncaught RichApi.Error: unknown" when executed in web browser #1654

Closed dhoelzl closed 7 months ago

dhoelzl commented 3 years ago

Message from office-js bot: We’re closing this issue because it has been inactive for a long time. We’re doing this to keep the issues list manageable and useful for everyone. If this issue is still relevant for you, please create a new issue. Thank you for your understanding and continued feedback.

When insertOoxml is called in a task pane in an Office-Add-In in a web browser in Office on the web (e.g. a current version of Google Chrome or Microsoft Edge on office.com), the XML won't be inserted and the following exception is generated, regardles of the input the method was given:

word-web-16.00.js:27 Uncaught RichApi.Error: unknown
    at new n (https://appsforoffice.microsoft.com/lib/1.1/hosted/word-web-16.00.js:26:300393)
    at n.i.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/1.1/hosted/word-web-16.00.js:26:361435)
    at https://appsforoffice.microsoft.com/lib/1.1/hosted/word-web-16.00.js:26:359540
    at async <anonymous>:10:4
    at async <anonymous>:1:1

Example code (reads the XML of the current selection, prints the XML to console and duplicates it in the document by inserting it at the current selection range):

await Word.run(async (context) => {

   var sourceRange = context.document.getSelection();
   var contentToCopy = sourceRange.getOoxml();
   await context.sync();

   console.log(contentToCopy.value);

   sourceRange.insertOoxml(contentToCopy.value, 'After');
   await context.sync();
});

When exactly the same code is executed in a native Office application (e.g. in a current version of Word 365 for Mac) it works as expected.

The script is included by

<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js"></script>

The issue seems to have occured already in the past but does not work at the time writing this issue (2021/02/22):

https://stackoverflow.com/questions/52092107/word-insertooxml-method-returning-error-unknown-for-all-input

Expected Behavior

insertOoxml works also in the web browser

Current Behavior

insertOoxml always causes exception and does not work when executed in a web browser in Office for the web

Steps to Reproduce, or Live Example

Context

This issue is very critical as it blocks all features requiring to insert document XML (e.g. document property fields) into the document.

Your Environment

RuoyingLiang commented 3 years ago

Thanks for reaching us. I use the insertOoxml to insert some content in Word Online and it works well. Could you share with me the xml content you inserted so we can try to repro the issue?

dhoelzl commented 3 years ago

Thank you for looking at this!

I can reproduce it by creating a new default document, entering the simple text "TEXT" without any additional formatting, selecting that text and executing the following code:

await Word.run(async (context) => {

   var sourceRange = context.document.getSelection();
   var contentToCopy = sourceRange.getOoxml();
   await context.sync();

   console.log(contentToCopy.value);

   sourceRange.insertOoxml(contentToCopy.value, 'After');
   await context.sync();
});

This code should duplicate the selected "TEXT" in the document.

The following is logged to console (the Ooxml to be inserted):

OOXML.txt

Office Online Build: 16.0.13925.41019

Browser: Google Chrome 88.0.4324.192 (Official build) (x86_64)

RuoyingLiang commented 3 years ago

Hi @dhoelzl , I've tried the script in our environment. Unfortunately we still cannot repro the issue. I record a video of my repro steps https://1drv.ms/v/s!AsJHyJBDS6CQi_hHTUwFm3cjmig7jQ?e=Wq3wSN . (The video record with Chrome in Win, I also tried with Chrome in Mac). Could you check if my repro step miss anything?

Could you also provide your session id (in the document, choose File->About) which can repro this issue? We will check if there is error information we can look into. Thanks!

dhoelzl commented 3 years ago

Thank you!

What version of Office do you use?

When running the Script on office.com (16.0.13924.41001) I cannot reproduce the problem, but when running it in our installation environment (16.0.13928.41017) the problem occurs. Could there be other differences beyond that version number?

Session ID: 5ca42178-4ead-407e-b143-537d1b3fd0dd Version: 16.0.13928.41017

At the bottom line, Inner Ring (Fastfood): FF3 is displayed.

RuoyingLiang commented 3 years ago

My version is 16.0.13928.41017, I'm using OneDrive. Do you mean your Office is installed in your own host?

dhoelzl commented 3 years ago

No, we do not host Office, we use the WOPI discovery URL for testing/developing: https://ffc-onenote.officeapps.live.com/hosting/discovery (as documented here: https://wopi.readthedocs.io/en/latest/build_test_ship/environments.html#discovery-urls)