Pass parameters when run js

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
George87
Posts: 9
Joined: Wed Aug 24, 2016 8:33 am

Pass parameters when run js

Post by George87 » Mon Feb 18, 2019 12:40 pm

Hello!
For running Test.js I type in address line: imacros://run/?m=Test.js.
Can I pass some parameters to Test.js in address line? For example, imacros://run/?m=Test.js?a=1&b=2?

I run iMacros for FireFox automatically. I can not pass parameters manually.
Now I must create several typical js-files. Each one has code with specific parameter value. For example:
Test1_1.js has a=1 and b=1
Test1_2.js has a=1 and b=2
Test2_1.js has a=2 and b=1
Test2_2.js has a=2 and b=2
That is why it will be very useful, if I can run Test.js with sending off parameters! :D

P.S.
I can not show my real js-file. But I think that main idea of my question is in above-mentioned example.

iMacros 9.0.3
Firefox 49 (Multiprocess windows disabled/enabled)
Windows 7x32
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Pass parameters when run js

Post by chivracq » Tue Feb 19, 2019 5:48 am

George87 wrote:
Mon Feb 18, 2019 12:40 pm
Hello!
For running Test.js I type in address line: imacros://run/?m=Test.js.
Can I pass some parameters to Test.js in address line? For example, imacros://run/?m=Test.js?a=1&b=2?

I run iMacros for FireFox automatically. I can not pass parameters manually.
Now I must create several typical js-files. Each one has code with specific parameter value. For example:
Test1_1.js has a=1 and b=1
Test1_2.js has a=1 and b=2
Test2_1.js has a=2 and b=1
Test2_2.js has a=2 and b=2
That is why it will be very useful, if I can run Test.js with sending off parameters! :D

P.S.
I can not show my real js-file. But I think that main idea of my question is in above-mentioned example.

Code: Select all

iMacros 9.0.3 
Firefox 49 (Multiprocess windows disabled/enabled)
Windows 7x32
"imacros://run/?m=Test.js?a=1&b=2" => Nope, this Syntax doesn't work, easy to test yourself, and you'll get some RuntimeError about "Test.js?a=1&b=2[.iim] not being found"...
Trying to put some Space in-between doesn't work either. -> Syntax Error..., and only the Scripting Interface supports a '-var_XXX xxx' Parameter.

For the rest of your Post/Qt, I can think of at least half a dozen ways to pass a Var to a '.js' (or '.iim) Script, but your Scenario is a bit too vague (I don't understand what you mean for example with "I run iMacros for FireFox automatically.") to explain them all in details for all Cases especially the most appropriate one(s) for your Case, and that would take too much time so I will only mention them "quickly"...

1- The "Purpose" of a '.js' Script is to handle any Conditional Logic (and Looping and Repetition of what can be repeated) "yourself". You didn't want to post what your '.js' is doing but if you need several similar '.js' Scripts with for each just a tiny-mini-Difference, your '.js' Script sounds "badly" implemented to me and probably simply needs one extra Level of (Nested) Looping... (At the Outer Level...)

2- URL of the current Page (from where you start your Script) can still be used to pass some extra Parameters but it needs a "real" URL, so you need to use some Web-Site that will accept your "fake" URL (and won't redirect you to some '404' or similar Page) and will keep your URL untouched, so that you can retrieve it from your Script with '!URRLCURRENT'.

3- Can use some '.CSV' or '.TXT' File as a DataSource.

4- Can open some local '.TXT' or '.HTM' File from your Script to extract its Content.

5- Can use any Site where you will have previously used some Input Field for your Parameters. (+ 'EXTRACT')

6- Can use the OS Clipboard:
6a- With Content put manually.
6b- From a '.BAT' File with 'clip.exe'.
6c- From a '.BAT' File with 'NirCmd.exe'.
6d- From PowerShell.
Interesting Thread on SOF about all '6[b-c-d]-' Options: Access clipboard in Windows batch file

7- Instead of '1-' you could handle the Vars and the different "Sub-" '.js' Script from another "main" '.js' Script on top of your existing one. But I consider it "Bad" Practice, you can better include that part like I mentioned in '1-'. And for passing Vars from one '.js' Script to another one, you'll need to use one of the Methods mentioned in '2-'/'3-'/'4-'/'5-' anyway...

8- If your Parameters are always going [1-1][1-2][2-1][2-2], it's not difficult to compute them directly from your existing Script. Could even be done from one single Script in pure '.iim', you don't even need a '.js' Script.

OK, "good luck" and post some Update with the Solution (and Script) you'll have chosen and implemented... :wink:

And/or give more Details about your complete Scenario and Requirements for me to be able to do some "Thinking" with you, there is very probably a much simpler way to implement those, as I have the "Feeling" you are going for a pretty "cumbersome" Implementation... (like 80% of Users on this Forum using '.js' Scripts anyway, ah-ah...!) :P
- (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...
George87
Posts: 9
Joined: Wed Aug 24, 2016 8:33 am

Re: Pass parameters when run js

Post by George87 » Tue Feb 19, 2019 2:54 pm

Thank you very much for such detailed answer :!:
I knew a much new tools! :D
I will use all your variants in my different projects. :idea:
You helped me very greatly!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Pass parameters when run js

Post by chivracq » Tue Feb 19, 2019 4:19 pm

George87 wrote:
Tue Feb 19, 2019 2:54 pm
Thank you very much for such detailed answer :!:
I knew a much new tools! :D
I will use all your variants in my different projects. :idea:
You helped me very greatly!
Oh...!, my "such detailed answer" was actually the "short" Version, ah-ah...! 8)

That Sentence I don't understand: "I knew a much new tools!" :?

Yeah well, about all different "Options" I've mentioned, avoid Nb '7-' about calling a '.js' from a '.js', this is very "Bad Practice" and only means (to me at least) that your Implementation has been poorly thought, and I can't think of any Usecase/Scenario where this cumbersome Way could be justified... Hum, and you are using v9.0.3 for FF, I'm not completely sure, but I thought the "Trick"/Syntax needed didn't work anymore in that Version and only worked until v8.9.7.

But OK, good luck further, and like I already mentioned, it would be nice for this Thread if you could post your Chosen Solution for this current Scenario and your Final Script on how you will have implemented it, as that would probably be useful for other Users... :idea:
- (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...
Post Reply