SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.95k stars 1.23k forks source link

Bootstrap error: Failed to execute write on Document (...) an asynchronously-loaded external script #3052

Open mauriciolauffer opened 3 years ago

mauriciolauffer commented 3 years ago

OpenUI5 version: All NPM versions

Browser/version (+device/version): Chrome, Edge, Firefox, IE

Any other tested browsers/devices(OK/FAIL): FAIL

URL (minimal example if possible): https://github.com/mauriciolauffer/openui5-sample-app/blob/doc-write-issue/webapp/index.html

Steps to reproduce the problem:

  1. Open a terminal;
  2. $ git clone https://github.com/mauriciolauffer/openui5-sample-app.git
  3. $ git checkout doc-write-issue
  4. $ npm install
  5. $ npm start
  6. Open http://localhost:8080/index.html
  7. Open DevTools (F12)
  8. Check browser consoles for errors

What is the expected result? UI5 bootstrap loaded successfully.

What happens instead? It does not load, there is an error. Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened. The error only happens when using async defer: script async defer id="sap-ui-bootstrap"

Any other information? (attach screenshot if possible) The error happens in sap-ui-core.js file due to statement document.write in lines 44, 48 and 52.

image

flovogt commented 3 years ago

Hi @mauriciolauffer ,

Thank you for sharing this finding. I've created an internal incident 2070425614. The status of the issue will be updated here in GitHub.

Best Regards, Florian

Note: Don't forget to switch the branch with git checkout doc-write-issue to start the app with the adjustments.

codeworrior commented 3 years ago

This is not a final answer, but rather a comment:

The development version of sap-ui-core.js can only be used within the head of a document. It is not intended for other scenarios. The problem is with the long-established sync contract of the bootstrap script. To make it work within the body, we could have used sync XHR and eval, but that felt even worse.

There are plans to establish an async alternative, but the feature set of it has not been agreed upon (should it guarantee the same APIs as sap-ui-core.js to make migration easy - an sap-ui-core-async.js so to say - or should it be much smaller, following the direction of UI5 evolution thinking? A prototype of the latter can be found under the name sap-ui-boot.js, but it's not a public offering.

mauriciolauffer commented 3 years ago

@flovogt Thanks 👍

@codeworrior I've notice this sap-ui-boot.js a while ago, when I first got the reported error. I was wondering why it isn't being used... Thanks for the comments

flovogt commented 2 years ago

This issue will be covered in backlog item CPOUI5FOUNDATION-382.