How to use Eval JS in imacros 10?

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

How to use Eval JS in imacros 10?

Post by groundfalling » Thu Sep 13, 2018 6:57 am

iMacros 10.0.2.1450 Free
Firefox 61.0.1
Ubuntu 16.0.4

This Eval macros worked fine in imacros 8.9.7

Code: Select all

SET !EXTRACT NULL
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=SPAN ATTR=CLASS:user-link EXTRACT=TXT
SET pass EVAL("if (\"{{!EXTRACT}}\" == \"#EANF#\") {var x = 'ctrl';} else {var x = '';} x;")
EVENT TYPE=KEYPRESS CHAR="w" MODIFIERS={{pass}}
but i need to use it with imacros 10.0.2.1450 in JS, i tried this:

Code: Select all

macroCode += 'SET !EXTRACT NULL\n';
macroCode += 'SET !EXTRACT_TEST_POPUP NO\n';
macroCode += 'TAG POS=1 TYPE=SPAN ATTR=CLASS:user-link EXTRACT=TXT\n';
macroCode += 'SET pass EVAL(\"if (\\\"{{!EXTRACT}}\\\" == \"#EANF#\") {var x = 'ctrl';} else {var x = '';} x;\")\n';
macroCode += 'EVENT TYPE=KEYPRESS CHAR="w" MODIFIERS={{pass}}\n';
but keep getting error at SET EVAL line. Can someone please share the correct syntax to use EVAL in JS with imacros 10. Thank you
Last edited by groundfalling on Thu Sep 13, 2018 12:28 pm, edited 2 times in total.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to use Eval JS in imacros 10

Post by chivracq » Thu Sep 13, 2018 11:52 am

groundfalling wrote:

Code: Select all

iMacros 10.0.2.1450
Firefox 61.0.1
Ubuntu 16.0.4 
This Eval macros worked fine in imacros 8.9.7

Code: Select all

SET !EXTRACT NULL
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=SPAN ATTR=CLASS:user-link EXTRACT=TXT
SET pass EVAL("if (\"{{!EXTRACT}}\" == \"#EANF#\") {var x = 'ctrl';} else {var x = '';} x;")
EVENT TYPE=KEYPRESS CHAR="w" MODIFIERS={{pass}}
but i need to use it with imacros 10.0.2.1450 in JS, i tried this:

Code: Select all

macroCode += 'SET !EXTRACT NULL\n';
macroCode += 'SET !EXTRACT_TEST_POPUP NO\n';
macroCode += 'TAG POS=1 TYPE=SPAN ATTR=CLASS:user-link EXTRACT=TXT\n';
macroCode += 'SET pass EVAL(\"if (\\\"{{!EXTRACT}}\\\" == \"#EANF#\") {var x = 'ctrl';} else {var x = '';} x;\")\n';
macroCode += 'EVENT TYPE=KEYPRESS CHAR="w" MODIFIERS={{pass}}\n';
but keep getting error at SET EVAL line. Can someone please share the correct syntax to use EVAL in JS with imacros 10. Thank you
Oh...!, I thought you were sharing a 'How-to'... => When asking a Qt, you can put some '?' to your Thread Title, I would think... :?

Nearly perfect for FCI but when using v10.0.x for CR/FF, you need to mention as well if you are using the 'Free'/'PE' Version...
=> v10.0.2.1450 'Free' for FF in your Case...

Before I go "digging" into the 'EVAL()', would be "handy" if you mentioned the "Error" maybe..., but User Defined Vars are not supported in the 'Free' Version as a "Start"...
+ The 'EVENT' Mode is also not supported anymore in v10.0.2 for FF, you'll need to use the Syntax/Solution I already gave you if you want a "Conditional CLOSE"..., or any other Solution that doesn't involve the 'EVENT' Mode..., but 'Ctrl^w' is not going to work...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

Re: How to use Eval JS in imacros 10

Post by groundfalling » Thu Sep 13, 2018 12:25 pm

I'm just trying to close the TAB in case the

Code: Select all

macroCode += 'TAG POS=1 TYPE=SPAN ATTR=CLASS:user-link\n';
is not found.
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

Re: How to use Eval JS in imacros 10

Post by groundfalling » Thu Sep 13, 2018 12:27 pm

you'll need to use the Syntax/Solution I already gave you if you want a "Conditional CLOSE"..., or any other Solution that doesn't involve the 'EVENT' Mode..., but 'Ctrl^w' is not going to work...
I need the macro to find the condition and if condition is not met, it should close the Tab.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to use Eval JS in imacros 10?

Post by chivracq » Thu Sep 13, 2018 12:48 pm

groundfalling wrote:I'm just trying to close the TAB in case the

Code: Select all

macroCode += 'TAG POS=1 TYPE=SPAN ATTR=CLASS:user-link\n';
is not found.
groundfalling wrote:
you'll need to use the Syntax/Solution I already gave you if you want a "Conditional CLOSE"..., or any other Solution that doesn't involve the 'EVENT' Mode..., but 'Ctrl^w' is not going to work...
I need the macro to find the condition and if condition is not met, it should close the Tab.
OK, but you won't achieve that using the 'EVENT' Mode...!

Did you check the Thread I referred you to yesterday...!?
If your (Conditional) Tab/Window CLOSE doesn't work in pure '.iim', there is no use to try to convert/adapt a non-working Solution to JS... :shock:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

Re: How to use Eval JS in imacros 10?

Post by groundfalling » Fri Sep 14, 2018 7:54 am

@chivracq thank you for the info, actually my target is not to close the tab or window, i have been trying to use !EXTRACT in EVAL in imacros 10.0.2.1450 (free) in JS format to make it work in .htm and than use it to check a condition and either break the current macro or call a new macro.
i see that you are an EVAL expert but i know you like to use it raw and not in JS.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to use Eval JS in imacros 10?

Post by chivracq » Fri Sep 14, 2018 3:37 pm

groundfalling wrote:@chivracq thank you for the info, actually my target is not to close the tab or window, i have been trying to use !EXTRACT in EVAL in imacros 10.0.2.1450 (free) in JS format to make it work in .htm and than use it to check a condition and either break the current macro or call a new macro.
i see that you are an EVAL expert but i know you like to use it raw and not in JS.
Yeah well, then maybe it would "help" if you used some "concrete" and "real" Example of what you really want, when I see an Example where you use a User Defined Var for the 'EVAL()', and meant to reuse for the 'EVENT' Mode, both not supported in v10.0.2 ('Free'), then there is no use to try to "correct" the 'EVAL()', it will never work anyway...

About "raw and not in JS", actually the Syntax I use for "my" 'EVAL()' Statements can also be reused directly in JS without any Modification at all in maybe 80% of the cases as I usually don't use any Special Chars that need to be escaped like Double Quotes for example... (well, unless there is a Double Quote as part of the String I want to "handle", then I'm forced to take care of it, of course...).

But say for example, you want 'EVAL()' to return a "1"/"0" if your Element is found/not found..., to maybe reuse for a 'TAG POS=1/0' in the next 'TAG' Statement, in pure '.iim', I would use:

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z; if(s!='#EANF'){z=1;} else{z=0;}; z;")
PROMPT VAR1:<SP>_{{!VAR1}}_
=> ... and you can reuse it as is in your JS if you use Single Quotes for your 'macroCode' String:

Code: Select all

macroCode += 'SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z; if(s!='#EANF'){z=1;} else{z=0;}; z;")\n';
macroCode += 'PROMPT VAR1:<SP>_{{!VAR1}}_\n';
By alternating Single and Double Quotes, you don't need to escape anything I would expect...

And to "break" your Macro, I don't know how iMacros now "behaves" with this JS/'.html' Method, with a first Macro aborting on some Element not found or 'MacroError()', if the JS on the '.html' Page is able to "take over" and continue Processing the 2nd Macro, you'll have to try..., or you need to split your Macro into smaller junks and handle the Conditional Workflow from the JS part, or you can "mute" the rest of your Macro for example with the "0" from the 'EVAL()' with 'POS=0' which won't do anything...
Or you can compute a "1"/"2" instead and reuse it to conditionally switch to a fake/dummy 'TAB_2' (already open) where the rest of your Macro won't do anything... (That's a good Workaround btw for a Conditional 'REFRESH', but it doesn't work on a 'TAB OPEN' or 'TAB CLOSE' that will always be executed, no matter on which TAB your Script is...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

Re: How to use Eval JS in imacros 10?

Post by groundfalling » Sat Sep 15, 2018 3:26 am

sorry this is not working

Code: Select all

macroCode += 'SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z; if(s!='#EANF'){z=1;} else{z=0;}; z;")\n';
when i use this the macro does not even start, so there is something wrong with this.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to use Eval JS in imacros 10?

Post by chivracq » Sat Sep 15, 2018 3:43 am

groundfalling wrote:sorry this is not working

Code: Select all

macroCode += 'SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z; if(s!='#EANF'){z=1;} else{z=0;}; z;")\n';
when i use this the macro does not even start, so there is something wrong with this.
Ah OK..., this would work normally in an (iMacros) '.js' Script (using v8.9.7) I think, then I guess the "Rules" and Syntax for a '.js' Script and "pure" JS embedded in an '.html' Page are "a bit" different, and you are back to escaping all the Single/Double Quotes, oops...!
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

Re: How to use Eval JS in imacros 10?

Post by groundfalling » Sat Sep 15, 2018 4:10 am

yes in iMacros 10, this has worked for me

Code: Select all

macroCode += 'SET !VAR1 EVAL(\"var s=\\"{{!EXTRACT}}\\"; var z; if(s==\\"#EANF#\\"){z=1;} else{z=0;}; z;\")\n';
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

Re: How to use Eval JS in imacros 10?

Post by groundfalling » Sat Sep 15, 2018 4:20 am

and to pass a string this syntax worked:

Code: Select all

macroCode += 'SET !VAR1 EVAL(\"var s=\\"{{!EXTRACT}}\\"; var z; if(s==\\"#EANF#\\"){z=\\"FOUND\\";} else{z=\\"NOTFOUND\\";}; z;\")\n';
macroCode += 'PROMPT {{!VAR1}}\n';
groundfalling
Posts: 46
Joined: Tue Jul 01, 2014 1:26 pm

Re: How to use Eval JS in imacros 10?

Post by groundfalling » Sat Sep 15, 2018 6:01 am

so imacros 10 free for FF
does not load any about page

Code: Select all

url goto=about:home
url goto=about:blank
url goto=about:preferences
it does not load any javascript

Code: Select all

URL GOTO=javascript:this.focus();self.opener=this;self.close()
doesn't give any error just doesn't do anything

and it also does not allow to save anything

Code: Select all

SAVEAS TYPE=EXTRACT FOLDER=/home/dir/dir FILE=save.txt
for SAVEAS it gives out an error to install something.

im not sure which of these restrictions are by firefox quantum and which are by imacros 10.
Post Reply