Run ruby from javascript isn't work

Run ruby from javascript isn’t work. It’s happened when I put the code used to run Ruby inside Window.onload
The first time opening htmlDialog, the code is working properly but when I close the htmlDialog then reopen it . The code is not working.

My Javascript:

window.onload = (event) => {
	sketchup.puts_string("window onload")

My .rb file:

$dialog.add_action_callback("puts_string") { |action_context, string|
	puts string.to_s

How to make it work?
Thank you in advance!

Read the first sentence - the “Note:…” - in documentation: HtmlDialog #add_action_callback method.
DO NOT USE global variable!!!


Thanks a lot! I didn’t notice that note.