Sketchup.is_online inside HtmlDialog callback on Mac

I came across a surprising issue recently as I am in the process of transitioning all my existing extensions to use exclusively HtmlDialogs instead of WebDialogs.

By now, most of us are aware of the broken SU2018 behavior where Sketchup.is_online will return false even if you are online. But the issue I will describe below is different.

The issue I am seeing is this:
If I call ‘Sketchup.is_online’ inside a callback (add_action_callback block) of an HtmlDialog, SketchUp will hang forever. For me, this issue only occurs in SU2017, SU2018 Mac only.

Is this a known issue? I could not find any reference to it in the api issue tracker github repo nor could I find any reference to it in a quick cursory search of SketchUp’s release notes.

def hang_html

  dlg =
  dlg.add_action_callback("hang") { 
    if Sketchup.is_online
	  puts "I'm online"
	  puts "I'm offline"
  dlg.set_html('<a href="#" onclick="sketchup.hang();">Test Hang</a>')


hm… I wasn’t aware of this. But I’m not surprised to be honest. CEF communication make this kind of stuff a challenge. I think also using Sketchup::Http within an action callback will cause problems.

You might be able to work around this by doing a zero length UI.timer to defer the call to Sketchup.is_online.

In general though I avoid using Sketchup.is_online or similar. Instead try to make the HTTP connection and handling the error. (Sketchup.is_online is simply making an HTTP requests and testing that it succeeds, so doing an HTTP request before you do an HTTP request is rather redundant.) This is similar to how you would deal with files, even if you check if a file exist or is readable before you open it there is no guaranty your next call will succeed. The most robust method with HTTP and file calls is try and then handle potential errors.

1 Like

Thanks Thom - I would like to avoid using Sketchup.is_online but it is very convenient since it is synchronous and I don’t need to rely on a specific URL to ping to test whether an HTTP request would succeed or not.

In my case, I am trying to test whether the user is online before opening a HtmlDialog hosted from a remote URL