String search ".startsWith" and ".includes"

This if_v2 stopped working in version 7.0.11 (tested in 6.3.3 without issues):
NOTE: To do make it even simpler this does not work either in “if_v2”: ((‘hello’).startsWith(‘el’)) == true
NOTE: It seems we have two different javaScript versions now in Kantu that do not support the functions below in “IF_v2” but in “execute”
The following JavaScript function I found so far stopped working in IF_v2:

  • .startsWith
  • .includes

Line 2: Error in condition of if_v2: undefined is not a function

   {
  "Command": "store",
  "Target": "Some Text",
  "Value": "myDescription",
  "Description": ""
},
{
  "Command": "if_v2",
  "Target": "${myDescription}.startsWith('Hello') == true",
  "Value": "",
  "Description": ""
},
{
  "Command": "echo",
  "Target": "Hallo world",
  "Value": "",
  "Description": ""
},
{
  "Command": "end",
  "Target": "",
  "Value": "",
  "Description": ""
}

:fox_face: startsWith () is an ES6 feature so it does not run in the “updated” executeScript_Sandbox.

The ES5 replacement of “startsWith” is lastIndexOf ("startsWithThis", 0) === 0

Example: We test if the string starts with “fox” :fox_face::

{
  "Name": "lastindexof",
  "CreationDate": "2022-5-18",
  "Commands": [
    {
      "Command": "store",
      "Target": "fox fox fox",
      "Value": "searchme",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "fox",
      "Value": "searchfor",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var haystack1 = ${searchme}; var needle = ${searchfor};  return (haystack1.lastIndexOf(needle, 0) === 0);",
      "Value": "result",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${result} ",
      "Value": "green",
      "Description": "TRUE because the string starts with FOX"
    },
    {
      "Command": "store",
      "Target": "ox",
      "Value": "searchfor",
      "Description": "Try again with a new search string"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var haystack1 = ${searchme}; var needle = ${searchfor};  return (haystack1.lastIndexOf(needle, 0) === 0);",
      "Value": "result",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${result} ",
      "Value": "blue ",
      "Description": "FALSE because the string does NOT start with FOX"
    },
    {
      "Command": "store",
      "Target": "fox",
      "Value": "searchfor",
      "Description": "Now use it inside IF"
    },
    {
      "Command": "if_v2",
      "Target": "${searchme}.lastIndexOf(${searchfor}, 0) === 0",
      "Value": "",
      "Description": "test if string SEARCHME starts with SEARCHFOR"
    },
    {
      "Command": "echo",
      "Target": "string found!",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "else",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "string NOT found!",
      "Value": "pink",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

:cat: .includes () is also an ES6 feature so it does not run in the “updated” executeScript_Sandbox.

The ES5 replacement of “.includes” is lastIndexOf ("searchForThis") >= 0

Example: We test if the string contains “cat” :cat::

{
  "Name": "includes",
  "CreationDate": "2022-5-18",
  "Commands": [
    {
      "Command": "store",
      "Target": "fox dog cat",
      "Value": "searchme",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "cat",
      "Value": "searchfor",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var haystack1 = ${searchme}; var needle = ${searchfor};  return (haystack1.lastIndexOf(needle)  > 0);",
      "Value": "result",
      "Description": ".includes done with lastIndexOf ES%"
    },
    {
      "Command": "echo",
      "Target": "${result} ",
      "Value": "green",
      "Description": "TRUE because the string contains CAT"
    },
    {
      "Command": "if_v2",
      "Target": "${searchme}.lastIndexOf(${searchfor}) >= 0",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "cat found!",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "else",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "cat NOT found!",
      "Value": "pink",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

Thanks for providing a work around for the issue.

Thanks, it’s just… I have over 300 macros and I found over 50 places where I have to do those changes. :/.

Yeah, I understand. Doing such maintenance work is not really fun. This manifest 3 transition turns out to be more tricky than expected. Little pitfalls everywhere. We spent over 3 months meanwhile just adapting to the new manifest v3 :frowning:

But… it seems like we are done soon, and then have a future-proof open-source RPA software.

Thank you.
I still think you guys are doing a great work and I’m grateful for that!

I have one more question:
Why is it not possible to run ES6 in the “executeScript_Sandbox”? Therefore it would the javascript version would be consistent all over the Kantu environment.

1 Like

With manifest V3 Chrome blocks the execution of the JS “eval” command inside any Chrome extension.

So we needed an alternative way to run Javascript and found JS-Interpreter - it is a nice piece of software but it only supports ES5.

If anyone knows a better JS interpreter that we can use, please let us know :wink:

Got it. Thanks for clarification!