Error in executescript_sandbox: error line 1: unexpected token (1:32)

Hello, i have a customer WhatsApp web conversation opened on browser, and i want to wait for him to send me a 5 digits code which i want to extract and store…

i was able to store the last received message and using while loop, check if this message have a 5 digits code or not, if not it keeps looping until it finds the code then it store it in variable… here is the working script:

{
“Name”: “version 2 while loop”,
“CreationDate”: “2025-6-25”,
“Commands”: [
{
“Command”: “store”,
“Target”: “”,
“Value”: “TT”,
“Description”: “”
},
{
“Command”: “while”,
“Target”: “${TT} == ""”,
“Value”: “TT”,
“Description”: “”
},
{
“Command”: “storeText”,
“Target”: “xpath=(//div[contains(@class,‘copyable-text’)]//span[@dir])[last()]”,
“Value”: “lastMessage”,
“Description”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “var match = ${lastMessage}.match(/\b\d{5}\b/); return match ? match[0] : ‘’;”,
“Value”: “TT”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “OTP Code: ${TT}”,
“Value”: “green”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
}
]
}

now my next goal is to extract all messages received by the customer (usually i only have like 3 to 4 very short messages since i clear unwanted chat beforehand), combine them together into one text with a space separation between each message, then store the combined text in a variable, once this step is finished i can proceed to next step… but unfortunately it is not working, im getting an error: error line 1: unexpected token (1:32) when the maros try to execute sanbox command

here is the macro script:

{
“Name”: “Extract_All_Messages”,
“CreationDate”: “2024-06-24”,
“Commands”: [
{
“Command”: “executeScript_Sandbox”,
“Target”: “var messages = […document.querySelectorAll(‘div.copyable-text span[dir]’)];\nvar combined = messages.map(m => m.innerText.trim()).join(’ ');\nreturn combined;”,
“Value”: “TT”
},
{
“Command”: “echo”,
“Target”: “All messages: ${TT}”,
“Value”: “green”
}
]
}

please can someone help me
thank in advanced

 {
      "Command": "executeScript",
      "Target": "var els = document.querySelectorAll('div.copyable-text span[dir]'); var result = ''; for (var i = 0; i < els.length; i++) { result += els[i].innerText.trim() + ' '; } return result.trim();",
      "Value": "TT",
      "Description": ""
    }

this works but gives error
Error in executeScript code: Refused to evaluate a string as JavaScript because ‘unsafe-eval’ is not an allowed source of script in the following Content Security Policy directive:

use storeXpathCount and loop through all