Trying to get popup created to load in a frame with chrome extension.

835 views
Skip to first unread message

Christopher Syroid

unread,
Jan 1, 2017, 6:28:05 PM1/1/17
to Chromium-Extensions-Announce
I'm trying to load a popup a page makes into a frame instead of a new window via chrome extension.
The code below works with TamperMonkey and GreaseMonkey but when I try executing it in a chrome extension it doesn't work and instead loads a popup window like normal.

Here's what I've got in inject.js:

var ifr;

window
._open = window.open;
window
.open=function(url,name,params){

   
if(url===('')||url.includes('adk')){

        lastW
= window._open(url,name,params);
       
return lastW;
   
}

   
if(!ifr)
        ifr
= document.createElement('iframe');  
    ifr
.src=url.replace('http','https');
    ifr
.sandbox='allow-forms allow-scripts';
    document
.body.appendChild(ifr);  
   
return ifr.contentWindow;
};

PhistucK

unread,
Jan 2, 2017, 1:46:05 AM1/2/17
to Christopher Syroid, Chromium-Extensions-Announce
You are not mentioning how you run this (the name seems to imply, but names can be confusing), so I assume it is a normal content script, so -
window.open cannot be overriden from within the context of the content script, you have to inject your script into the page (append a script element with the URL of the script, you can use chrome.runtime.getURL in order to get an absolute URL) so it would run in the context of the page.
(Also, content scripts have a bug where they cannot access contents of iFrames, but injected scripts can)


PhistucK

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/8f65f768-3f24-462a-9936-a5ef731fc990%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Christopher Syroid

unread,
Jan 2, 2017, 2:58:18 AM1/2/17
to Chromium-Extensions-Announce, chris...@gmail.com
I inject this onto the page. What happens is the script watches for a loaded popup and loads it into an iframe. When I test it with this code:

window._open = window.open("http://www.google.com", "_blank", "height=200,width=200");

It works. But when I try to click on a link to open a new window, Chrome just opens up a new window anyway and from what I can see from the console, there's no errors.
The only thing I can think of is this snippet of code isn't working properly:



PhistucK

To post to this group, send email to chromium-...@chromium.org.

PhistucK

unread,
Jan 2, 2017, 3:02:46 AM1/2/17
to Christopher Syroid, Chromium-Extensions-Announce
Could it be that the link is opening a new window/tab using target=_blank instead of window.open?
Or is this a popup?

Have you debugged those conditions?
Did you set breakpoints at the body of the if statement? Do you see that something returns a truthy value where it makes no sense?


PhistucK



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.

Christopher Syroid

unread,
Jan 2, 2017, 3:23:10 AM1/2/17
to Chromium-Extensions-Announce, chris...@gmail.com
I'm 100% sure it's a popup. When I add breakpoints to the if statement, I get nothing.


PhistucK



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

PhistucK

unread,
Jan 2, 2017, 4:06:35 AM1/2/17
to Christopher Syroid, Chromium-Extensions-Announce
If you set breakpoints in the beginning of the overridden function, does it break?
There may be many reasons, for example, the page may have cached window.open for later use before you overrode it.
Try to debug the page code that opens that popup and see what is going on.


PhistucK



PhistucK



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
Reply all
Reply to author
Forward
0 new messages