openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

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

Open mauriciolauffer opened this issue 5 years ago • 4 comments

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

mauriciolauffer avatar Oct 21 '20 05:10 mauriciolauffer

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.

flovogt avatar Oct 22 '20 08:10 flovogt

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.

codeworrior avatar Oct 22 '20 09:10 codeworrior

@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

mauriciolauffer avatar Oct 27 '20 05:10 mauriciolauffer

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

flovogt avatar Mar 02 '22 13:03 flovogt