The reason why it's broken seems to be because dynamic scripts are not guaranteed to run immediately and in the order they were inserted (so the a:last-of-type selector always selects the same node).
The way to avoid this potential footgun is to make DOMHelper.insertScript return a promise that resolves on load, but for this particular case, I think it's better to just run a single script instead.
The reason why it's broken seems to be because dynamic scripts are not guaranteed to run immediately and in the order they were inserted (so the
a:last-of-type
selector always selects the same node).The way to avoid this potential footgun is to make
DOMHelper.insertScript
return a promise that resolves on load, but for this particular case, I think it's better to just run a single script instead.