How to set variable Web Widget duration from within widget

Is there a way to manage dynamic duration for web widgets? We would like to display widgets that load data dynamically, and duration has to be variable depending on the quantity of content to be displayed within the widget. Is there anyway to close a Web widget once it has finished displaying data and not before? Can Javascript from within widget communicate somehow with the player and notify it to close the widget and continue with next item on playlist?

There is a feature request for this, but it hasn’t been implemented currently.