It is possible to use the widget yaml to include scripts, both inline and loaded from source. This is not widely advertised and definitely not officially supported (and not likely to ever be, for obvious reasons), but it can be done. I’m not sure it’s going to solve this particular problem, however, as passing data between the widget context script and the mainUI backend is non-trivial.