OfficeDev / script-lab

Create, run and share your code directly from Office
MIT License
703 stars 161 forks source link

Dialog (on office for web) immediately fails if it contains an office script reference #1017

Closed justmars closed 1 year ago

justmars commented 1 year ago

Bug Report

Expected behavior:

With the following snippet on scriptlab:

$("#run").click(() => tryCatch(run));

async function run() {
  await Office.context.ui.displayDialogAsync('https://localhost:3000/test')
}

async function tryCatch(callback) {
  try {
    await callback();
  } catch (error) {
    console.error(error);
  }
}

This ought to be visible on the dialog box after Office.context.ui.displayDialogAsync runs:

<html>
  <head>
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
  </head>
  <body>
    <h1>hello world</h1>
  </body>
</html>

Actual behavior:

In Office for Web, the dialog window immediately closes upon opening. But if I remove <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>, the dialog window remains open.

Note that in desktop Mac, the dialog window remains open.

Steps to Reproduce:

  1. Open a Word document using office.com and run scriptlab
  2. Run a third-party app serving the following url https://localhost:3000/test with html indicated under Expected behavior
  3. Add snippet to scriptlab indicated under Expected behavior
  4. Click on run on scriptlab
justmars commented 1 year ago

Apparently, my localhost was serving the dialog url ('https://localhost:3000/test') with the response header Cross-Origin-Opener-Policy: same-origin-allow-popups. Once i switched this off, the dialog url was able to properly load the OfficeJS reference in the head.