I have a java script/chrome extension that simulates clicks from a commercial web page, that works fine in the chrome console. But when I run it from the extension, I get "onUpdate is not a function", which is referring to a callback (onclick="return onUpdate();) referenced in the popped up page html.
Popped up page html
<div id="divButtons" align="left" style="position: relative; z-index: 10;">
<table border="0" cellspacing="0" cellpadding="0" width="97%" summary="">
<tbody><tr>
<td class="swlErrorMessage" id="errorStatus">Ready</td>
</tr>
<tr>
<td><font size="1"> </font></td>
</tr>
<tr align="right">
<td>
<input type="button" class="button" value="OK" name="ok" onclick="return onUpdate();" title="">
<input type="button" class="button" value="Cancel" name="cancel" onclick="return onCancel();" title="">
</td>
</tr>
</tbody></table>
I think I figured out where the break is. Basically, if I run the code in console at once, it works fine. But if I manually click on the link and then use the chrome extension to target the window, it performs everything correctly other than the save, and I noticed in my code, when I run the window.open and target the name, that seems to break any reference back to the main page and it's like it doesn't have any reference to any of the previous callbacks. If I open the chrome console on the page that was popped up, run the window.open again, and execute the code, it all works.
Not sure why everything but this one function isn't working. onUpdate().
I have ran it from the console and it works fine.
code.js
function cfs_all(){
var x = document.getElementById('tabFrame');
var y = x.contentDocument ;
var link = y.getElementById('urlListTable');
link = link.getElementsByTagName('tr');
runLoop = async() => {
for(a=0;a<link.length;a++){
await new Promise(resolve => setTimeout(resolve, 2000))
if (link[a].children[1].innerText.includes('Allow') == true){
console.log('Yesssssssssss '+ String(a))
var rest = y.getElementsByTagName('tr')
rest = rest[a+2].getElementsByTagName('td')
//simulates the button click to open the pop up window
rest[3].getElementsByTagName('img')[0].click()
setTimeout(function(){
//connects to the popped up window
var test;
var text = "*.test.edu"
test = String(window.origin)
test = test.substring(8,)
test = test.replace(/\:.*/,'');
test = test.split('.')
//opens the window by referencing the window.name
var existingWin = window.open('', test[0]+ "_" + test[1] + "_" + test[2] + "_" + test[3] + "_urlObjDlg");
console.log(test[0]+ "." + test[1] + "." + test[2] + "." + test[3])
//clicks add, opens textbox
existingWin.document.getElementsByClassName('button')[0].click()
//adds the value to the text box
existingWin.document.getElementsByTagName('input')[9].value = text
//clicks save button
try{
existingWin.document.getElementsByClassName('button roundBtn swlEventSave')[0].click()
}
catch(err){
existingWin.document.getElementsByClassName('button roundBtn swlEventClose')[0].click()
}
//updates the page, THIS IS WHAT's NOT WORKING!!!
existingWin.onUpdate;
}, 1500);
}
else
{
console.log('Nooooooo ' + String(a))
}
}
}
runLoop()
}
cfs_all()
I can paste the above code in and it works in the console
this is the code I have to paste in the popped up window's chrome console, and it works...
function cfs_add(){
var test;
test = String(window.origin)
test = test.substring(8,)
test = test.replace(/\:.*/,'');
test = test.split('.')
var existingWin = window.open('', test[0]+ "_" + test[1] + "_" + test[2] +
"_" + test[3] + "_urlObjDlg");
console.log(existingWin)
existingWin.onUpdate()
}
cfs_add()
It's the same code...