Shiny:sessioninitialized : Javascript on startup

rmarkdown
shiny

#1

My Rmarkdown/shiny document uses this code, to detect & report a zoom problem,
and write a "zoom advice" message.
Included in the UI with "includeScript('readInnerWindow.js')
It works fine on resize, but not initially when the page opens
(which is when I really need it).
Using shiny:connected instead of shiny:sessioninitialized --- same problem.
The initial alert never appears. The other JS code in the app is working fine.

copyDims = function(e) {
    Shiny.onInputChange("innerHeight", window.innerHeight);
    Shiny.onInputChange("innerWidth", window.innerWidth);
    alert('copyDims');
};

$(document).on('shiny:sessioninitialized', function(event) {
  alert('shiny:sessioninitialized');
});

$(document).on("shiny:sessioninitialized", copyDims);
$(window).resize(copyDims);