Yes but can you share the plugin script where did you put this? In which part?
You need to be sure element is loaded before triggering update part of the plugin.
This code is ran before the rest of your screen is loaded and is intended to be loading libraries/style sheets and other useful goodies you may need after the rest of your page loads.
You could shift that code to an action and only run the action when page load (entire) is true
That would delay the code from running until the image is also loaded. Unlesssss your image is not visible when the rest of the page is loaded anyway. In that case you’d want to wait until the image is visible to run that code snippet.