openHAB 4.3 feature request: support of external JS within oh-widgets

see https://community.openhab.org/t/widget-with-js-not-properly-loaded-displayed/155281

injecting Javascripts within Widgets is possible - but not natively supported by openHAB and therefore not robustly working:
“The ability to to do this is a side-effect of the widget system not an intentional feature. So, it is not officially supported and there’s every likelihood that errors like this will crop up”

Is there any chance to enable “Javascripting within Widgets” in one of the next openHAB releases?

O.

What is your use case for this?

currently I have 2 usecases:

  • chart.js as described in referenced thread
  • weather widget from forcast7.com
uid: WeatherJS
tags: []
props:
  parameterGroups: []
timestamp: Apr 11, 2024, 1:15:11 PM
component: f7-card
config: {}
slots:
  default:
    - component: a
      config:
        class: weatherwidget-io
        content: Markgröningen
        data-days: 5
        data-font: Arial Black
        data-icons: Climacons Animated
        data-label_1: Markgröningen
        data-theme: weather_one
        href: https://forecast7.com/de/48d909d09/markgroningen/
        style: width:100%;
    - component: script
      config:
        content: '!function(d,s,id){var
          js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://weatherwidget.io/js/widget.min.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","weatherwidget-io-js");
 

I am not familiar with the weather widget, but I don’t see any reason why you shouldn’t be able to make it work with a little bit of tweaking.

As for official support, you are welcome to put in a feature request on the Ui repository (or even propose and implement some PR that achieves what you are looking for), but I don’t think you’ll get what you’re after; there are just too many potential pitfalls for novice users to allow easy access to arbitrary code execution. In fact, a few recent changes have been made to limit some of the js in widget possibilities for security reasons. Those changes should not prevent you from running locally hosted js scripts (which is the work you would have to put in to getting the weather widget to run, I suspect).

Also, if you are comfortable with web server configuration it is possible for you to override the recent changes and allow OH to run scripts from other servers such as your weather script. But, this comes back around to there not being “official” support for such an action. It makes sense that this kind of activity needs to require a certain level of experience and understanding because the user who does this has to know and accept the risks for themselves.

Dear Justin,

thx. Saved the Widget-JS locally at html-share and changed the respective URL to “/static/libs/widget.min.js”.
No improvement - sometimes the widget is loaded properly, sometimes not.

Nevertheless thanks for your time.
O