简体   繁体   中英

Imacros/jQuery TypeError: can't access dead object, line 816 (Error code: -991)

I'm trying to write a iMacros script that uses jQuery but it seems that if I refresh the page I get

TypeError: can't access dead object, line 816 (Error code: -991)

This is my current code:

//Macros
refreshPage = "CODE:";
refreshPage += "SET !TIMEOUT_PAGE 30" + "\n";
refreshPage += "SET !ERRORIGNORE YES" + "\n";
refreshPage += "SET !TIMEOUT_STEP 2" + "\n";
refreshPage += "URL GOTO=somewebsite.com" + "\n";


    //Go to website
    iimPlay(refreshPage);

    //Main Code
    //Iclude jQuery
    function loadScriptFromURL(url) {
       var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
       async = false;
       request.open('GET', url, async);
       request.send();
       if (request.status !== 200) {
          var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
          iimDisplay(message);
          return false;
       }
       eval(request.response);
       return true;
    }
    loadScriptFromURL('https://www.dropbox.com/s/47cj0fqxnsijm2n/jquery-2.2.2.min.js?raw=1');
    $ = window.$,
       JQuery = window.JQuery;

    // Get List
    var jscList = [];
    var llcList = []; // not in use
    var companiesList = $('#companieshomelist').children();
    if (companiesList[0].innerText.match(/S.A./gi)) {
       for (var i = 1, j = companiesList.length; i < j; i++) {
          if (companiesList[i].innerText.match(/L.L.C/gi)) {
             break;
          } else {
             jscList.push(companiesList[i].innerText.split('\n')[0])
          }
       }
    }

    for (var i = 0, j = 1; i < j;i++) {
    iimPlay(refreshPage);
     foo() // script still works, foo can be anything js code/iMacros code and it works.
    companiesList[i+1].click(); // script throws dead object error, seems to happen if I try to use ANY jQuery code after page is refreshed 

    }

I thought maybe jquery needed to be loaded again so I tried moving it around, duplicating it, even included it in a function called refresh that included the refresh macro so it's loaded right after the page refresh but the result was the same everything. Quite new at jQuery as you can probably tell by the code so I have no idea how to fix this or even what the issue is.

I'm open to any alternative ways to use/load jQuery with Mozilla.

FF/Mozilla 45.0.1// iMacros 8.9.6// Windows 7// jQuery 2.2.2.min.js //

As a possible solution I just rewrote your script so that it might use the jQuery libs already loaded on the web page.

//Macros
refreshPage = "CODE:";
refreshPage += "SET !TIMEOUT_PAGE 30" + "\n";
refreshPage += "SET !ERRORIGNORE YES" + "\n";
refreshPage += "SET !TIMEOUT_STEP 2" + "\n";
refreshPage += "URL GOTO=somewebsite.com" + "\n";

//Go to website
iimPlay(refreshPage);

// Get List
function getList() {
    var jscList = [];
    var llcList = []; /* not in use */
    var companiesList = $('#companieshomelist').children();
    if (companiesList[0].innerText.match(/S.A./gi)) {
       for (var i = 1, j = companiesList.length; i < j; i++) {
          if (companiesList[i].innerText.match(/L.L.C/gi)) {
             break;
          } else {
             jscList.push(companiesList[i].innerText.split('\n')[0])
          }
       }
    }
}

window.location.href = "javascript:{" + getList.toString() + "getList(); undefined;}";
iimPlayCode("WAIT SECONDS=0.3");

for (var i = 0, j = 1; i < j;i++) {
    iimPlay(refreshPage);
    foo() // script still works, foo can be anything js code/iMacros code and it works.
    window.location.href = "javascript:{" + getList.toString() + "getList(); companiesList[" + (i + 1) + "].click(); undefined;}";
    iimPlayCode("WAIT SECONDS=0.3");
}

I didnt play attention to the full error and it seemed I had 2 issues as shugar pointed out in a comment. jQuery had to be loaded again after refresh and companiesList had to be defined again for some reason.

function loadJQ() {
    function loadScriptFromURL(url) {
        var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
        async = false;
        request.open('GET', url, async);
        request.send();
        if (request.status !== 200) {
            var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
            iimDisplay(message);
            return false;
        }
        eval(request.response);
        return true;
    }
    loadScriptFromURL('https://www.dropbox.com/s/47cj0fqxnsijm2n/jquery-2.2.2.min.js?raw=1');
    $ = window.$,
    JQuery = window.JQuery;
}
loadJQ()    

var jscList = [];
var llcList = []; // not in use
var companiesList = $('#companieshomelist').children();
if (companiesList[0].innerText.match(/S.A./gi)) {
    for (var i = 1, j = companiesList.length; i < j; i++) {
        if (companiesList[i].innerText.match(/L.L.C/gi)) {
            break;
        } else {
            jscList.push(companiesList[i].innerText.split('\n')[0])
        }
    }
}

for (var i = 0;i < 1;i++) {
iimPlay(refresh)
loadJQ()
companiesList = $('#companieshomelist').children();
companiesList[i+1].click(); 

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM