Issue with Sandbox in new Firefox release

Now back to the original question: How to run your regex “replace” code in Firefox:

    {
      "Command": "executeScript_Sandbox",
      "Target": "var string = '$8,495'; var stripped = string.replace(/[^0-9]/g, \"\"); return stripped;",
      "Value": "test",
      "Description": ""
    },

=> There are two solutions for E501 in Firefox:

(1) use executeScript instead of executeScript_Sandbox.

(2) Or replace whatever the regex does with “normal” Javascript code, then it works. Here is an example:

{
  "Name": "testregex",
  "CreationDate": "2024-5-3",
  "Commands": [
    {
      "Command": "executeScript",
      "Target": "var string = '$8,495'; var stripped = string.replace(/[^0-9]/g, \"\"); return stripped;",
      "Value": "test1",
      "Description": "works in Chrome/Edge and Firefox"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var string = '$8,495';\nvar stripped = '';\n\n// Loop through each character in the string\nfor (var i = 0; i < string.length; i++) {\n    var char = string[i];\n    // Check if the character is a digit\n    if (char >= '0' && char <= '9') {\n        stripped += char; // Add only digits to the stripped string\n    }\n}\n\nreturn stripped;\n",
      "Value": "test2",
      "Description": "regex replaced => works in sandbox in Firefox, too"
    },
    {
      "Command": "echo",
      "Target": "2) _Sandbox (Workaround for FX): ${test2} ",
      "Value": "green",
      "Description": ""
    }
  ]
}
1 Like