iMacros doesn't display an error message

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
acajo
Posts: 8
Joined: Sat Oct 17, 2015 12:43 pm

iMacros doesn't display an error message

Post by acajo » Sat Apr 20, 2019 5:38 pm

Hello, I'm using:
- Firefox 49.0.2
- iMacros for Firefox 8.9.7
- Windows 10
- Javascript macro

//My whole macro is divided into functions, for example:
function a(){...}
function b(){...}
function c(){...}
//Macro starts with a call to the first function:
window.setTimeout(a,0);
//function a() at the end calls function b() with window.setTimeout(b,0);
//every other function at the end calls the next function or itself if I want a loop etc...
//This is my solution to avoid "for" loops blocking browser
//JS macro has 10 000 lines of code
//Problem: When I throw error inside function called by setTimeout, iMacros doesn't display an error message on the sidebar and freezes
//I'm completely lost when error occurs
//Thank you in advance
chivracq
Posts: 8761
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros doesn't display an error message

Post by chivracq » Sat Apr 20, 2019 6:49 pm

acajo wrote:
Sat Apr 20, 2019 5:38 pm
Hello, I'm using:

Code: Select all

- Firefox 49.0.2
- iMacros for Firefox 8.9.7
- Windows 10
- Javascript macro
//My whole macro is divided into functions, for example:

Code: Select all

function a(){...}
function b(){...}
function c(){...}
//Macro starts with a call to the first function:
window.setTimeout(a,0);
//function a() at the end calls function b() with window.setTimeout(b,0);
//every other function at the end calls the next function or itself if I want a loop etc...
//This is my solution to avoid "for" loops blocking browser
//JS macro has 10 000 lines of code
//Problem: When I throw error inside function called by setTimeout, iMacros doesn't display an error message on the sidebar and freezes
//I'm completely lost when error occurs
//Thank you in advance
Yep-yep, I "like" the "Principle" of dividing and calling your whole Workflow with different 'Functions', I consider it "neat" and "Good Practice", and handily "modular"... 8)

But hum, to be able to give you any "Advice", you would need to post a bit how you "build" your Functions and how you use 'iimPlay(Code)()' and 'iimGetLastError()' + 'iimDisplay()' within/around the different Functions... I would need to see your Script to be able to have an "Opinion", and if I have any Feedback/Idea/Recommendation...
It could be that the 'setTimeout()' is acting a bit as a "Wrapper" around the 'iimDisplay()' and is blocking the "Communication" between the Script and the iMacros Panel for the Display Functionality, but I guess you would then have the same "Pb" already with 'iimPlay()'... :?

I don't really relate to your "//This is my solution to avoid "for" loops blocking browser" also btw, what do you mean...?
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
acajo
Posts: 8
Joined: Sat Oct 17, 2015 12:43 pm

Re: iMacros doesn't display an error message

Post by acajo » Sat Apr 20, 2019 10:01 pm

Hello Chivracq, thank you for your fast reply.

I will simplify the problem:

Code: Select all

//test.js
aler("Hello");
//iMacros returns error
//ReferenceError: aler is not defined, line 4 (Error code: -991);

Code: Select all

//test2.js
window.setTimeout(function(){aler("Hello");},0);
//Nothing
chivracq
Posts: 8761
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros doesn't display an error message

Post by chivracq » Sat Apr 20, 2019 10:07 pm

acajo wrote:
Sat Apr 20, 2019 10:01 pm
Hello Chivracq, thank you for your fast reply.

I will simplify the problem:

Code: Select all

//test.js
aler("Hello");
//iMacros returns error
//ReferenceError: aler is not defined, line 4 (Error code: -991);

Code: Select all

//test2.js
window.setTimeout(function(){aler("Hello");},0);
//Nothing
Yeah well, normal I would think, the Name is "alert()" and not "aler()"... :?

EDIT:
Ah OK, sorry...!, I understand, the Typo on 'alert()' is on purpose..., OK, let me "think"...! :wink:
Last edited by chivracq on Sat Apr 20, 2019 10:12 pm, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
acajo
Posts: 8
Joined: Sat Oct 17, 2015 12:43 pm

Re: iMacros doesn't display an error message

Post by acajo » Sat Apr 20, 2019 10:12 pm

chivracq wrote:
Sat Apr 20, 2019 10:07 pm
Yeah well, normal I would think the Name is "alert()" and not "aler()"... :?
This was made on purpose to demonstrate that iMacros doesn't report error when error occurs inside setTimeout callback.
EDIT:
I guess that I need some sort of global error handler in iMacros js script, but I don't really know how to do it, what is the top scope etc...
chivracq
Posts: 8761
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros doesn't display an error message

Post by chivracq » Sat Apr 20, 2019 10:37 pm

acajo wrote:
Sat Apr 20, 2019 10:12 pm
chivracq wrote:
Sat Apr 20, 2019 10:07 pm
Yeah well, normal I would think the Name is "alert()" and not "aler()"... :?
This was made on purpose to demonstrate that iMacros doesn't report error when error occurs inside setTimeout callback.
EDIT:
I guess that I need some sort of global error handler in iMacros js script, but I don't really know how to do it, what is the top scope etc...
Yeah-yeah, I had realized (a bit late, ah-ah!) that your "Typo" was on purpose...

But hum, what you are seeing is "pure" JS Behaviour from the FF JS Engine, it is not specific to iMacros (for FF).
I get the same Result if I "mutilate" the "alertFunc" into "alertFun" for example on the "myVar = setTimeout(alertFunc, 1000);" Line on this JS 'Try me' Site for example...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
acajo
Posts: 8
Joined: Sat Oct 17, 2015 12:43 pm

Re: iMacros doesn't display an error message

Post by acajo » Sun Apr 21, 2019 10:12 am

chivracq wrote:
Sat Apr 20, 2019 10:37 pm
But hum, what you are seeing is "pure" JS Behaviour from the FF JS Engine, it is not specific to iMacros (for FF).
if you tried my simplified examples you can see that iMacros reports "pure" JS errors too, but it doesn't in the case of setTimeout and I need this desperately.
chivracq
Posts: 8761
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros doesn't display an error message

Post by chivracq » Sun Apr 21, 2019 2:11 pm

acajo wrote:
Sun Apr 21, 2019 10:12 am
chivracq wrote:
Sat Apr 20, 2019 10:37 pm
But hum, what you are seeing is "pure" JS Behaviour from the FF JS Engine, it is not specific to iMacros (for FF).
if you tried my simplified examples you can see that iMacros reports "pure" JS errors too, but it doesn't in the case of setTimeout and I need this desperately.
Yeah, but iMacros handles itself the "Erroring" coming from all iMacros 'iimXxx()' Commands and lets the JS Engine handle the "pure" JS Code, and if the JS Engine doesn't return any Error apparently with 'setTimeout()', then iMacros cannot return anything either.

You can see the same Behaviour also with 'EVAL()' in '.iim' Scripts, there are 3 Levels of Erroring, one at Parsing time that will usually only detect "Syntax" Errors in 'EVAL()' itself and a few but not all in Methods used in that 'EVAL()' Expression, and 2 at Execution time with 1 returning "the rest" of the Syntax Errors inside the Methods used in the 'EVAL()' Expression + "some" Errors like Reference missing, Var not defined etc..., and 1 that won't "complain" about what is happening inside 'EVAL()', but 'EVAL()' won't do anything, and with no "Explanation" why... That's the way it works... :|
Same with the 'URL GOTO=javascript:' Syntax also actually...

Concerning 'setTimeout()', I don't know if it's "by Design" or if it is a Flaw in that Method, I've actually seen it in some Cases being used "on purpose" as some kind of Workaround to deliberately achieve that "Sandboxing" Functionality, a bit like '!ERRORIGNORE' in '.iim' Scripts.

But in your Case, for detecting Reference and Definition Errors that the JS Engine can detect "natively" like "aler()"/"alert()", you should first run and test/debug your Functions natively in pure JS before calling them from 'setTimeout()' once you know that 'setTimeout()' has this Sandboxing Effect...

You may want to check and/or open a (parallel) Thread on SOF (Stackoverflow Forum) where there is much more Knowledge about JS than on our Forum, especially if/as your Qt is pure JS... :idea:
(And post the Link here, I'll be interested to "follow", and other Users also probably... (But I will see it on SOF if you include the 'imacros' Tag in your Qt... :wink: ))
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply