Bug when calling javascript from javascript

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
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
abxy01
Posts: 6
Joined: Sun Oct 27, 2013 6:25 am

Bug when calling javascript from javascript

Post by abxy01 » Tue Nov 05, 2013 8:02 am

I'm trying to call several javascripts from parent javascript by iimPlay("CODE:URL GOTO=imacros://run/?m=name.js") command.
Example 1:

Code: Select all

var storage = window.localStorage;
storage['indx']='_'; // global variable
for (var i = 0; i < 5; i++) 
    { 
    storage['indx']='_'+i;
    iimPlay("CODE:URL GOTO=imacros://run/?m=test.js");
    }
----------------
       {test.js}

var storage = window.localStorage;
mtext = 'Prompt Hellow<SP>'+storage['indx'];
iimPlay('code:'+ mtext);
Return
if option "Show javascript when playing” is ON :
Hellow _0
Hellow _4
if option "Show javascript when playing” is OFF :
Hellow _0
Example 2:

Code: Select all

var storage = window.localStorage;
storage['indx']='_'; // global variable
for (var i = 0; i < 5; i++) 
    { 
    storage['indx']='_'+i;
    iimPlay("CODE:URL GOTO=imacros://run/?m=test.js");
    mtext = 'Prompt Bye!<SP>'+storage['indx'];
    iimPlay('code:'+ mtext);
    }
----------------
       {test.js}

var storage = window.localStorage;
mtext = 'Prompt Hellow<SP>'+storage['indx'];
iimPlay('code:'+ mtext);
Return
if option "Show javascript when playing” is ON :
Hellow _0
Bye! _0
Bye! _1
Bye! _2
Bye! _3
Bye! _4
if option "Show javascript when playing” is OFF :
Bye! _0
Bye! _1
Bye! _2
Bye! _3
Bye! _4
I tried different versions of FF and iMacros:
1. iMacros 8.5.1, iMacros 8.5.3 beta
2. Windows 7 Professional
3. Firefox 22 and 24
Tom, Tech Support
Posts: 3527
Joined: Mon May 31, 2010 4:59 pm

Re: Bug when calling javascript from javascript

Post by Tom, Tech Support » Tue Nov 05, 2013 12:43 pm

Hi abxy01,

I've reproduced the behavior you are encountering and noted a couple of additional things:
  • Using the code from the first example, it does not matter how many loops there are, the iimPlay call in the loop only works for the first and last iteration of the loop. All the other calls result in iimPlay returning error code -1001 (Unknown error).
  • Even if you don't use a loop and instead list multiple calls to iimPlay on separate lines, only the first and last succeed.
  • If instead of attempting to call a .js script with URL GOTO, you instead call an .iim macro, then it works every time.
  • If you add an alert statement within the loop, e.g. alert(i), then each call to iimPlay succeeds.
Unfortunately, there isn't anything we can do about this at this time. Please see the note that I just added to this post.
Regards,

Tom, iMacros Support
abxy01
Posts: 6
Joined: Sun Oct 27, 2013 6:25 am

Re: Bug when calling javascript from javascript

Post by abxy01 » Tue Nov 05, 2013 2:16 pm

Thank You for answer, Tom

This examples was used to demonstrate the problem. In fact I have a task on my job - to make external library of complex javascript functions to call they from different scripts. You didn’t recognize one more abnormality: if You make iimPlay('code: …') in the end of code, only first .js succeed.

P.S. We automate our system with web-interface, which works well only in Firefox, so we can't use iMacros Enterprise edition for Internet Explorer
Tom, Tech Support
Posts: 3527
Joined: Mon May 31, 2010 4:59 pm

Re: Bug when calling javascript from javascript

Post by Tom, Tech Support » Tue Nov 05, 2013 2:55 pm

abxy01 wrote:P.S. We automate our system with web-interface, which works well only in Firefox, so we can't use iMacros Enterprise edition for Internet Explorer
Ah, but you can also use the iMacros scripting interface available in the Enterprise Edition to automate iMacros for Firefox! It's a fairly simple matter of calling iimOpen("-fx").
Regards,

Tom, iMacros Support
Post Reply