gss / engine

GSS engine
http://gss.github.io
MIT License
2.86k stars 105 forks source link

CDN-provided gss.js doesn't parse when inlined #206

Open du5t opened 8 years ago

du5t commented 8 years ago

I was testing bundling up a single-file HTML webapp with html-lnline, and found a couple spots where Chrome can't load gss.js if its contents are in <script> tags inline:

Engine.prototype.getWorkerURL = (function() {
    var scripts, src;
    if (typeof document !== "undefined" && document !== null) {
      scripts = document.getElementsByTagName('script');
      src = scripts[scripts.length - 1].src;
      if (!src.match(/gss/i)) {
        scripts = document.querySelectorAll('script[src*=gss]')[0];
        if (scripts && scripts.hasOwnProperty('length')) {              // MODIFIED HERE: threw error because scripts was undefined
          src = scripts[0].src;
        }
      }
    }
    return function(url) {
      if (typeof url !== 'string') {
        url = src;
      }
      if (!url) {throw new Error("Can not detect GSS source file");} // MODIFIED HERE: some ILLEGAL character was appearing
      return url;
    };
  })();

html-inline was otherwise faithful in inserting the script; fixing the above two lines in the bundled HTML file resulted in a working bundle.