Javascript function giving error

it gives error Unexpected token (1:20)
tried 2 ways

 {
      "Command": "store",
      "Target": "\"aaaaa\"",
      "Value": "aa",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "let title = ${aa};\n\nif (title.charAt(0) === '\"' && title.charAt(title.length - 1) === '\"') {\n    title = title.slice(1, -1);\n}\n\nreturn title;\n",
      "Value": "aa",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "let title = ${aa};\n\nif (article_title.startsWith('\"') && article_title.endsWith('\"')) {\n    title = article_title.slice(1, -1);\n}\n\nreturn title;",
      "Value": "aa",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${aa}",
      "Value": "",
      "Description": ""
    }

The issue is that executeScript_Sandbox supports only the older ES5 Javascript commands.

ā†’ Solution: Asking ChatGPT/Claude/Mistral/Gemini/Grok to convert the code to ES5 Javascript solves the issue:

{
  "Name": "ES5",
  "CreationDate": "2025-3-5",
  "Commands": [
    {
      "Command": "store",
      "Target": "\"aaaaa\"",
      "Value": "aa",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var title = ${aa};\n\nif (title.charAt(0) === '\"' && title.charAt(title.length - 1) === '\"') {\n    title = title.slice(1, -1);\n}\nreturn title;\n",
      "Value": "aa",
      "Description": "You must use only ES5 compatible Javascript"
    },
    {
      "Command": "echo",
      "Target": "${aa}",
      "Value": "",
      "Description": ""
    }
  ]
}

changing let to var fixed it according to your code

1 Like