executeScript or executeScript_Sandbox or storeEval gives the same error.
Used to be ok before v5.
{
"Name": "test_replace",
"CreationDate": "2019-6-11",
"Commands": [
{
"Command": "executeScript",
"Target": "return [\"a\",\"b\",\"c\"]",
"Value": "var"
},
{
"Command": "executeScript",
"Target": "${var}.replace(/b/g,\" \")",
"Value": "var"
}
]
}
upd. Issue appears with Array only
upd 2.
Sorry this is my mistake. Replace does not work with an Array. Thanks @howard_chu for making it obvious to me. I c/p piece of my code neglecting the type of variables.
The correct working code is:
{
"Name": "test_replace",
"CreationDate": "2019-6-11",
"Commands": [
{
"Command": "executeScript",
"Target": "return [\"a\",\"b\",\"c\"]",
"Value": "var"
},
{
"Command": "executeScript",
"Target": "return ${var}.map(x => x.replace(/b/g,'X'))",
"Value": "var"
}
]
}
What about this (not tested):
"Target": "${var}.replace(/b/g,' ')",
Tried before posting, but it’s not the syntaxis. Worked both ways before v5.0.3
Oh great, that will knock-out my scrape, too. And that is a deal-breaker; I’ll have to go back to iMacros.
How about:
"Target": "var x = ''; x = '${var}'; x.replace(/b/g,' ')",
Hi, Replace works for me:
[echo] v1=abc, v2=axc
{
"Name": "replace",
"CreationDate": "2019-6-11",
"Commands": [
{
"Command": "store",
"Target": "abc",
"Value": "v1"
},
{
"Command": "executeScript",
"Target": "return ${v1}.replace('b','x')",
"Value": "v2"
},
{
"Command": "echo",
"Target": "v1=${v1}, v2=${v2}",
"Value": ""
}
]
}
@TheWhippinpost Tried ‘that’ too. No luck With correction. var x = ''; x = ${var}; x.replace(/b/g,' '); return x;
@howard_chu Yeah it narrows it down. Your var is String. Mine is Array.
I stand corrected. Issue appears with Array only.
I must have fucked it up.
Replace should not work with arrays right?
I must add forEach().
Complete idiot here. Sorry about that.
I copied it from my another macro I used a week ago neglecting that I defined a var from an array.
Once again sorry. My mistake. Working code here:
{
"Name": "test_replace",
"CreationDate": "2019-6-11",
"Commands": [
{
"Command": "executeScript",
"Target": "return [\"a\",\"b\",\"c\"]",
"Value": "var"
},
{
"Command": "executeScript",
"Target": "return ${var}.map(x => x.replace(/b/g,'X'))",
"Value": "var"
}
]
}
It happens; glad you got it working