In a .*eex file you can inject javascript into your elements as a string and it should work. For simple js I do this in my own heex sigils in .ex files. For example,
<button onclick="(() => document.documentElement.scrollTop = 0)()">
Scroll to top
</button>
If your html2canvas function is defined in the javascript bundle delivered to the client, then triggering the function you wrote as a string in your .*eex file should work.
In my opinion this shouldn't really be done for non-trivial js. If you are using Phoenix LiveView, look into hooks. You would write your custom js and trigger it off of a hook, or use a hook to push an event that you would handle server-side in Elixir.