After reviewing @hugronaphor's answer. In particular this link along with some jQuery 3.x discussions regarding changes to the ready and load events my final solution was in fact to remove my code from Drupal.behaviours
.
In the end I have implemented code in the following style:
(function ($, Drupal){
$(window).on("load",function() {
//Do something
});
})(jQuery, Drupal);
This gave me reliable access to the .on("load")
event again which is what I was after as I need the entire page to be loaded before I trigger the script.
As my script is relatively simple and doesn't need further context information I think this is fine for my use case.
I "think" the issue is related to the following change in jQuery 3.x where on("load")
is not guaranteed to fire inside a $(Document).ready
state any more - which is what Drupal.behaviours
is giving you. I am something of a js noob though so will leave it to smarter people to explain why this may or may not be the case. If there is a better answer I would like to hear it.
For my simple case not being in the Drupal.behaviour
has solved my issue.