[SOLVED]TypeError: can't access dead object

Discussions and Tech Support specific to the iMacros Firefox Add-on.
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
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

[SOLVED]TypeError: can't access dead object

Post by Trax » Mon Mar 21, 2016 3:58 pm

Seems I ran into a tiny issue with jQuery, everything works unless I refresh the page. Then I get :

Code: Select all

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

Code: Select all

/***************Settings************************


****************End of Settings*****************/


//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
companiesList[i+1].click(); // script throws dead object error, seems to happen if I try to use any jQuery code after refresh
	
}
Using latest everything/ firefox/imacros,jquery on Win 7 :)

PS I already tried moving around, even duplicating the whole jQuery script load.
Last edited by Trax on Thu Mar 31, 2016 7:04 am, edited 1 time in total.
vt2011
Posts: 35
Joined: Sat Jul 23, 2011 6:21 pm

Re: TypeError: can't access dead object, line 816 (Error cod

Post by vt2011 » Wed Mar 23, 2016 7:44 am

yup, I have the same error message too with native javascript, especially when I use an array of html element and use them later in the script liek in your case. I guess for any reason some faulty html element in the array can not be referenced anymore on the current page because the page content has refreshed dynamically therefore the array is not correct anymore. I did not try to fix this issue, I just encapsulate the faulty array in the try/catch statement to avoid the script to stop.
User avatar
thecoder2012
Posts: 405
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: TypeError: can't access dead object, line 816 (Error cod

Post by thecoder2012 » Wed Mar 23, 2016 9:52 am

Trax wrote:Seems I ran into a tiny issue with jQuery, everything works unless I refresh the page.
Load jQuery after every url goto in your imacros. Only once is not enough.
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: TypeError: can't access dead object, line 816 (Error cod

Post by Trax » Wed Mar 23, 2016 1:28 pm

thecoder2012 wrote:
Trax wrote:Seems I ran into a tiny issue with jQuery, everything works unless I refresh the page.
Load jQuery after every url goto in your imacros. Only once is not enough.
I've already tried that, I loaded it multiple times inside the loop too before and after the refresh, I even made a function that contained both the refresh code and load jQuery code .. same result
User avatar
thecoder2012
Posts: 405
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: TypeError: can't access dead object, line 816 (Error cod

Post by thecoder2012 » Wed Mar 23, 2016 2:09 pm

Trax wrote:I've already tried that, I loaded it multiple times inside the loop too before and after the refresh, I even made a function that contained both the refresh code and load jQuery code .. same result
Before is wrong for your loop!
Any testwebsite (or htmlcode) possible?
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: TypeError: can't access dead object, line 816 (Error cod

Post by Trax » Wed Mar 23, 2016 2:20 pm

Code: Select all

refreshPage += "URL GOTO=proeconomica.com" + "\n";
Would take about 1 min to make an account and test If you want but I doubt it's the page.


Full code here of latest attempt

Code: Select all

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


//Go to website
iimPlay(refreshPage);

//Main Code
//Iclude jQuery
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()	
// Get Companies 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])
		}
	}
}

function foo() {
	alert('here')
}
for (var i = 0, j = 1; i < j;i++) {
iimPlay(refreshPage);
	foo();
	loadJQ();
	//companiesList[i+1].click(); 
	$("[class=state_buy]").val("500");
	
}
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: TypeError: can't access dead object, line 816 (Error cod

Post by Trax » Mon Mar 28, 2016 9:19 am

Seems there 2 issues. First jQuery had to be loaded after each refresh and second the var containing the links (companiesList) had to be defined again after refresh too.
Post Reply