RPA v7.0.9 JS-Interpreter RegEx issue

I’m seeing issues with regex matching or replacing when using JS-Interpreter. This is on a site with a Content Security Policy that prohibits me simply switching to executeScript. It seems any regex usage that I could come up with, results in the empty {} object being returned. This example below works on RPA 6 and the statement also runs on the online JS-Interpreter demo.

{
  "Command": "executeScript_Sandbox",
  "Target": "return 'hello'.match(/(.)/)[0];",
  "Value": "result",
  "Description": ""
}

Alternatively, I see myself running into a lot of issues with the new interpreter since I have some existing scripts that scrape sites that I do not have any control over. I would be interested to know about any best practices that allow for using a more capable interpreter with scripts executing against sites with a CSP.

The new interpreter has a problem return objects or arrays. But it returns strings and integers just fine. So can you convert the object/array into a string and return this?

Another alternative: If CSP does not allow you to use executeScript, then the workaround is to open another website, and run executeScript there. This allows you to use the unmodified Javascript. The macro below shows a demo:

{
  "Name": "CSP",
  "CreationDate": "2022-5-4",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://github.com/A9T9",
      "Value": "",
      "Description": "Github has CSP so executeScript does not run there"
    },
    {
      "Command": "selectWindow",
      "Target": "TAB=OPEN",
      "Value": "https://ui.vision/",
      "Description": "Use any website without CSP "
    },
    {
      "Command": "executeScript",
      "Target": "var arr = []; for(var x = 0; x < 5; x++){arr[x] = []; for(var y = 0; y < 3; y++){arr[x][y] = (x+1)*(y+1);}}; return arr",
      "Value": "array1",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "TAB=CLOSE",
      "Value": "",
      "Description": "Done with executeScript, so close the dummy tab again"
    },
    {
      "Command": "csvSaveArray",
      "Target": "array1",
      "Value": "data_from_array.csv",
      "Description": ""
    },
    {
      "Command": "clickAndWait",
      "Target": "xpath=//li/div/div/div/a/span",
      "Value": "",
      "Description": "Continue our macro on the Github website"
    },
    {
      "Command": "click",
      "Target": "linkText=command-line",
      "Value": "",
      "Description": ""
    }
  ]
}

Thanks for the suggestion to block CSP with the extension. I would however prefer an alternative solution due to the security concerns.

I understand the interpreter issue with objects/arrays, but the original example should have been returning a string already, but is for some reason returning the empty object instead. Here is a more obvious example that is clearly returning a string, but still demonstrates the issue:

{
  "Name": "test",
  "CreationDate": "2022-5-4",
  "Commands": [
    {
      "Command": "executeScript_Sandbox",
      "Target": "var t = 'hello'.match(/(.)/)[0]; return 'test';",
      "Value": "notWorking",
      "Description": "This does not work, value is {} even though a string is clearly returned."
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var t = 'hello'.replace('he','c'); return 'test';",
      "Value": "thisWorks",
      "Description": ""
    }
  ]
}

It seems to me that any regex usage breaks what is ultimately returned.

Also, I appreciate the suggestion to open a dummy tab and run my more complex javascript processing there. Though that would be really great if your team could figure out a way for the tool to expose a more capable interpreter without requiring us to manually code the workaround each time it is needed.

Ok, I see the issue now. Thanks for this test case!

This issue is solved with V7.0.13. Thanks again for reporting it!