[Violation] Parser was blocked due to document.write(<script>)

1,980 views
Skip to first unread message

ajlo...@gmail.com

unread,
Nov 5, 2017, 6:28:36 PM11/5/17
to Clojure
Sorry - very basic... I am trying the Clojurescript quickstart guide, and have followed the instruction in detail.  When trying to view the index.html in Chrome, I get this error in the console:

"[Violation] Parser was blocked due to document.write(<script>)."

This happens when running this code in base.js:
  /**
   * Writes a new script pointing to {@code src} directly into the DOM.
   *
   * NOTE: This method is not CSP-compliant. @see goog.appendScriptSrcNode_ for
   * the fallback mechanism.
   *
   * @param {string} src The script URL.
   * @private
   */
  goog.writeScriptSrcNode_ = function(src) {
    goog.global.document.write(
        '<script type="text/javascript" src="' + src + '"></' +
        'script>');

I see the comments say this is not a CSP-compliant method  - - and it is probably the cause of the error.  I don't understand how to use the "fallback mechanism" mentioned? If that is the solution?
Please, any pointers would be greatly appreciated.

Laurens Van Houtven

unread,
Nov 5, 2017, 9:28:39 PM11/5/17
to clo...@googlegroups.com
How are you hosting it? Under what hostname? Localhost isn’t supposed to have a CSP, and I thought Chrome was smart enough to know localhost is a special origin. Can you post a minimal reproducer?

lvh

Thomas Heller

unread,
Nov 6, 2017, 2:01:39 AM11/6/17
to Clojure
This is only an issue in unoptimized code, ie. :none.

Without optimizations all code is in separate files which are loaded in dependency order. The default debug loader will load them by appending a script tag to the document. This has pretty terrible performance characteristics but is OK during development. You can pretty much ignore the chrome warning during development. You can turn off the "Verbose" log level and you won't see them again.

For everything non-development you should optimize the code with either :simple or :advanced settings, which will combine all the separate files into one (or more via :modules). This will not use the the debug loader and the warnings go away.

HTH

ajlo...@gmail.com

unread,
Nov 6, 2017, 5:35:35 PM11/6/17
to Clojure
Thanks, Laurens &Thomas

I have simply followed the instructions on this guide -- https://clojurescript.org/guides/quick-start -- up to the point before the section "Less Boilerplate" Where it says I should see the message "Hello World!" in the browser (Chrome) console.  I see nothing except the error in the Chrome dev tools console?  So it is just localhost, nothing fancy.  Windows 10, Chrome Version 61.0.3163.100 (Official Build) (64-bit).  Not sure how to post "minimal reproducer".
All I see in the console are these errors:  (Thomas,  I turned off verbose as you suggested and it hides the error, but then nothing else is displayed - it just hides the error (not warning it seems):



what 
Reply all
Reply to author
Forward
0 new messages