Hi, the problem is that document.getElementById($parameters.WidgetId) is returning null. So later is trying to do addEventListener of an null element and that's the error.
You should add a console.log of WidgetId and test on the console of the browser to verify what is its value and why is returning null document.getElementById of your widget
Kind regards