1

When I click a button on a commecercial site, it pops open a window. That window will be the ip address, plus some string text. I can get that name, then I use the js code from my content script, referencing a js file. Within that file, I then use window.open to reference the popup window. Everything works except that last callback onUpdate(). This callback is a part of the popped up window, which is what I need to access, so I can use the save function.

js

function cfs_add(){
var test;
var text = "*.test.com"
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(test[0]+ "." + test[1] + "." + test[2] + "." + test[3])
existingWin.document.getElementsByClassName('button')[0].click()
existingWin.document.getElementsByTagName('input')[9].value = text
try{
existingWin.document.getElementsByClassName('button roundBtn swlEventSave')[0].click()
}
catch(err){
existingWin.document.getElementsByClassName('button roundBtn swlEventClose')[0].click()
}
existingWin.onUpdate();
}
cfs_add()

I have a chrome extension that works fine when I run it from within the Javascript Context below. I need to access a function that is part of another page/window. Since I know it works in the console, I assume I'll need to use something like "iframe.contentDocument || iframe.contentWindow.document". The function I need to run is part of the website out of my domain, so I"m accessing it via window.open and referencing the elements within. But the onclick will not work and that's because the call back it's referencing is part of another window... I think. I'm sure because it works fine if I run in the javascript Context as in the picture. If I change to another context like Top, it gives me the same error my Chrome extension gives me.

Where can I find information about this window element and how to manipulate it within my chrome extension?

test

Jason Owens
  • 525
  • 2
  • 6
  • 21
  • 1
    Without a real [MCVE](/help/mcve) I'm not sure what exactly you're doing so I'll have to guess. The console runs in the main context of a page or iframe but content scripts run in *isolated world* and they can't access the main context. There's a workaround explained in [this answer](/a/9517879). – wOxxOm Sep 17 '19 at 17:40
  • I edited it to include what I'm trying to do. What I'm really getting at it what is that Javascript Context, in the DevTools window. It works fine if ran under "TabFrame" in the dev tools, Javascript Context, if I try to run it out of "Top", it won't. – Jason Owens Sep 17 '19 at 17:50
  • 1
    My guess seems to be right: to call `onUpdate` function defined by the page you'll need to add a script element to existingWin.document.documentElement, with `onUpdate()` text inside as explained in the answer I've linked above. – wOxxOm Sep 17 '19 at 17:59
  • I don't understand. And again, in the Javascript Execution Context, it works fine. Just when I change outside the view, it no longer finds the callback. Which suggestion on the following page are your referring to? It appears to me I should be able to reference the iframe, and the elements within them. – Jason Owens Sep 17 '19 at 18:03
  • Without a **real** MCVE (with manifest.json, file names, and other necessary info) I still have to guess so the conversation isn't very productive. I'm assuming you want to run that code in your content script. You can do it fine as I understand except for onUpdate call. My comments above explain what you need to do to call that function. – wOxxOm Sep 17 '19 at 19:11

0 Answers0