Webserver invoke trigger json crashes with nested objects

Describe the bug
Appearently, when trying to trigger the passed json with nested props (Trigger config) the BTT crashes and restarts

JSON:

{
  "BTTTriggerType" : 643,
  "BTTTriggerTypeDescription" : "Named Trigger: BTT_Node1",
  "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
  "BTTPredefinedActionType" : 153,
  "BTTPredefinedActionName" : "Move Mouse To Position",
  "BTTMoveMouseToPosition" : "{0, 0}",
  "BTTMoveMouseRelative" : "0",
  "BTTTriggerName" : "BTT_Node1",
  "BTTEnabled2" : 1,
  "BTTUUID" : "26F2E20A-57EE-45AA-B833-ED42B4DF37F1",
  "BTTEnabled" : 1,
  "BTTOrder" : 11,
  "BTTTriggerConfig" : {
    "BTTHUDText" : "hi",
    "BTTShowHUD" : 1
  }
}

Url that crashes BTT: http://127.0.0.1:64472/trigger_action/?json={\"BTTTriggerType\":643,\"BTTTriggerTypeDescription\":\"Named%20Trigger:%20BTT_Node1\",\"BTTTriggerClass\":\"BTTTriggerTypeOtherTriggers\",\"BTTPredefinedActionType\":153,\"BTTPredefinedActionName\":\"Move%20Mouse%20To%20Position\",\"BTTMoveMouseToPosition\":\"{0,%200}\",\"BTTMoveMouseRelative\":\"0\",\"BTTTriggerName\":\"BTT_Node1\",\"BTTEnabled2\":1,\"BTTUUID\":\"26F2E20A-57EE-45AA-B833-ED42B4DF37F1\",\"BTTEnabled\":1,\"BTTOrder\":11,\"BTTTriggerConfig\":{\"BTTHUDText\":\"hi\",\"BTTShowHUD\":1}}&shared_key=myKey

Url that works fine: http://127.0.0.1:64472/trigger_action/?json={\"BTTTriggerType\":643,\"BTTTriggerTypeDescription\":\"Named%20Trigger:%20BTT_Node1\",\"BTTTriggerClass\":\"BTTTriggerTypeOtherTriggers\",\"BTTPredefinedActionType\":153,\"BTTPredefinedActionName\":\"Move%20Mouse%20To%20Position\",\"BTTMoveMouseToPosition\":\"{0,%200}\",\"BTTMoveMouseRelative\":\"0\",\"BTTTriggerName\":\"BTT_Node1\",\"BTTEnabled2\":1,\"BTTUUID\":\"26F2E20A-57EE-45AA-B833-ED42B4DF37F1\",\"BTTEnabled\":1,\"BTTOrder\":11}&shared_key=myKey

Affected input device (e.g. MacBook Trackpad, Magic Mouse/Trackpad, Touch Bar, etc.):
Webserver

Device information:

  • Type of Mac: mbp 13" mid 2014
  • macOS version: 10.13.5
  • BetterTouchTool version: 2.517 alpha

Thanks for reporting, this will be fixed with the next alpha.

Btw. I don't think you need to escape quotes in urls.

1 Like

Thanks for the feedback, happy to hear that!

Yeah, probably escaping the {} is not necessary, though I was checking out what was the problem and that was the result of playing around :slight_smile:

@Andreas_Hegenberg the issue above has been resolved by the alpha as you said, but there are cases of even deeper nesting and BTT has crashed on those, too. Unfortunately I cannot find a specific JSON that caused the BTT to restart - but it had one level deeper nesting afair.

Weird, if you can find one that still crashes please let me know! I'm currently not able to reproduce it.

I've played around with it a little bit. Seems like BTTTriggerAdditionalActions isn't working properly:

{
  "BTTTriggerType" : -1,
  "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
  "BTTPredefinedActionType" : 24,
  "BTTPredefinedActionName" : "Volume Up",
  "BTTEnabled2" : 1,
  "BTTUUID" : "CFF20365-3E08-49D9-A789-C1888BFFED75",
  "BTTTriggerOnDown" : 1,
  "BTTEnabled" : 1,
  "BTTShortcutKeyCode" : -1,
  "BTTShortcutModifierKeys" : -1,
  "BTTOrder" : 103
}

:point_up: works

does not work :point_down:

{
  "BTTTriggerType" : -1,
  "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
  "BTTPredefinedActionType" : 24,
  "BTTPredefinedActionName" : "Volume Up",
  "BTTEnabled2" : 1,
  "BTTUUID" : "CFF20365-3E08-49D9-A789-C1888BFFED75",
  "BTTTriggerOnDown" : 1,
  "BTTEnabled" : 1,
  "BTTShortcutKeyCode" : -1,
  "BTTShortcutModifierKeys" : -1,
  "BTTOrder" : 103,
  "BTTAdditionalActions" : [
    {
      "BTTTriggerType" : -1,
      "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
      "BTTPredefinedActionType" : 25,
      "BTTPredefinedActionName" : "Volume Down",
      "BTTEnabled2" : 1,
      "BTTUUID" : "34A2E4C5-BF71-4366-A3BF-966AC2FDE310",
      "BTTEnabled" : 1,
      "BTTShortcutKeyCode" : -1,
      "BTTShortcutModifierKeys" : -1,
      "BTTOrder" : 370
    }
  ]
}

So this could be the issue i've experienced before, alfa 2.518

I didn't want to create another thread: also if you try to invoke an action that has emoji in it (in hud for example), it isn't triggered when called from websever. Perhaps they should be escaped, but I'm not sure if its up to client or backend.

I was able to reproduce and fix the crashing issue, but smilies seem to work fine here.

I tested with this json:

{
  "BTTTriggerType" : 643,
  "BTTTriggerTypeDescription" : "Named Trigger: 1",
  "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
  "BTTPredefinedActionType" : 5,
  "BTTPredefinedActionName" : "Mission Control",
  "BTTTriggerName" : "1",
  "BTTEnabled2" : 1,
  "BTTUUID" : "FEAEB628-E6A0-4360-8B03-97243246D6C1",
  "BTTEnabled" : 1,
  "BTTOrder" : 0,
  "BTTTriggerConfig" : {
    "BTTHUDText" : "😕",
    "BTTShowHUD" : 1
  }
}

http://127.0.0.1:60699/trigger_action/?json=http://127.0.0.1:60699/trigger_action/?json={%20"BTTTriggerType"%20:%20643,%20"BTTTriggerTypeDescription"%20:%20"Named%20Trigger:%201",%20"BTTTriggerClass"%20:%20"BTTTriggerTypeOtherTriggers",%20"BTTPredefinedActionType"%20:%205,%20"BTTPredefinedActionName"%20:%20"Mission%20Control",%20"BTTTriggerName"%20:%20"1",%20"BTTEnabled2"%20:%201,%20"BTTUUID"%20:%20"FEAEB628-E6A0-4360-8B03-97243246D6C1",%20"BTTEnabled"%20:%201,%20"BTTOrder"%20:%200,%20"BTTTriggerConfig"%20:%20{%20"BTTHUDText"%20:😕"BTTShowHUD"%20:%201%20}%20}

mh you are right, browsers seem to automatically escape the emojs then it doesn't work anymore... will check how to workaround

//edit I think I have a solution...
//edit2: yep working! Will release new version tomorrow.

1 Like

Awesome! Cannot wait to test it out, thank you for your support :tada:

Btw, I'm triggering the JSON from outside browser environment (I'm doing the fetch from nodejs env, so it's making a request fully in the background)

Should now be working in v2.520 alpha (which is very alpha, I hope I didn't break too much as there have been quite a few internal changes).

1 Like

Awesome! Gonna test in a minute, thanks :slight_smile:

Should this URL work?

http://127.0.0.1:64472/trigger_action/?json={"BTTPredefinedActionType":254,"BTTHUDActionConfiguration":"{\"BTTActionHUDDetail\":\"hi\",\"BTTActionHUDTitle\":\"hi\",\"BTTActionHUDDuration\":1,\"BTTActionHUDBackground\":\"114.773936,%20250.237260,%20120.947282,%2050.145815\",\"BTTActionHUDSlideDirection\":0}","BTTEnabled2":1,"BTTEnabled":1}&shared_key=myKey

This is the new showHUD action - I guess the webserver should invoke it, but it doesn't looks like it does

I just wanted to suggest that you could add the method to POST instead of GET to get the params, which would make passing the params a little bit more secure and perhaps some issues with JSON could go away, perhaps

EDIT: Seems like triggering such JSON somehow works ( i mean, hud shows but its empty ) :

{"BTTPredefinedActionType":254,"BTTHUDActionConfiguration":"{}","BTTEnabled2":1,"BTTEnabled":1}

While contrary - with configuration passed, nothing happens

Ah yes, sorry there was still an issue with some actions. It should now be working in v2.522.

Post requests should be easy to add, I'll look into this soon.

1 Like

Thanks! It works in latest alpha :slight_smile: