Chat.js . loadcss function breaks link to zammad domain

Source: chat.js . loadcss function breaks link to zammad domain · Issue #3654 · zammad/zammad · GitHub

info:

  • Used Zammad version: Zammad Version 4.1.x
  • This is related to the core files executed on a client borwser and not effected by server environment.

Problem: We want to add the chat tool to our homepage but loadCss is “messing” arround with the url of the domain hosting zammad.

Expected behavior:

wsrn.support goes in wsrn.support comes out.

Actual behavior:

Steps to reproduce the behavior:

Create a chat widget in zammad for a domain containing the letters “ws”, or “wss”

Copy the code to your page and enjoy!

Discussion

I guess the code below is responsible for this behaviour:

    /* chat.js */
    ZammadChat.prototype.loadCss = function() {
      var newSS, styles, url;
      if (!this.options.cssAutoload) {
        return;
      }
      url = this.options.cssUrl;
      if (!url) {

        /* the next line breaks our integration */
        url = this.options.host.replace(/^wss/i, 'https').replace(/^ws/i, 'http').replace(/\/ws/i, '');
        url += '/assets/chat/chat.css';
      }
      this.log.debug("load css from '" + url + "'");
      styles = "@import url('" + url + "');";
      newSS = document.createElement('link');
      newSS.onload = this.onCssLoaded;
      newSS.rel = 'stylesheet';
      newSS.href = 'data:text/css,' + escape(styles);
      return document.getElementsByTagName('head')[0].appendChild(newSS);
    };

source: zammad/chat.js at develop · zammad/zammad · GitHub

I don’t get why the replace function is there in the first place and even if there is a reason why anybody would think this is a good solution for this particular problem. I’m really curious about this part and it would be great to get some pointers.

I’m aware that I can solve the problem by using setting “cssAutoload” to false and adding an url for “cssUrl”, but I don’t believe this should be necessary.

Regards,

Patrick

Heads up - issue #3654 has been reopened and accepted.

Hi, thanks for reopening the issue. As it is going forward at gihub. I believe we close this topic hier

Thanks for your support.

Patrick