Search code examples
javascriptjqueryfirefoximacros

JavaScript won't work in iMacros (JQuery)


I am trying to mass unfollow in Twitter. I am using Firefox 55.0.2 64 bit on Windows 8.1 64 bit. It works, when I browse to https://twitter.com/following and then enter the following in the Developers console

$('.user-actions-follow-button').click()

Doing the above unfollows everyone on the page. But when I try in iMacros. It loads the page, then just sits there and times out after 60 seconds. No error is given. The code is as follows

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://twitter.com/following
URL GOTO=javascript:{$('.user-actions-follow-button').click();}

Solution

  • You no longer have access to this functionality. As per http://wiki.imacros.net/iMacros_for_Firefox#Version_History

    The following were never officially supported and had to be removed as well, since Firefox no longer allows access to the page DOM from the browser context (only frame scripts can do so now)

    • No access to webpage DOM from javascript in .js files (window, content objects) or macros (URL GOTO=javascript:...),

    So URL GOTO=javascript: doesn't work anymore.


    You could just loop over all Unfollow buttons like this:

    unfollow.js content:

    iimSet("var_url", "https://twitter.com/following");
    iimPlay("Open URL.iim");
    
    var count = 1;
    do {
        iimSet("var_loop", "R" + count);
        var result = iimPlay("unfollow.iim");
        count++;
    } while (result == 1);
    

    Open URL.iim content

    URL GOTO={{var_url}}
    

    unfollow.iim content

    TAG POS=1 TYPE=DIV ATTR=class:SidebarCommonModules
    TAG POS={{var_loop}} TYPE=BUTTON ATTR=TXT:Unfollow
    

    The JS Loop keeps running as long as the macro played successfully, i.e. returned 1. When it no longer does, there is nothing left to unfollow on the page right now and it ends with an element not found error.