nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.39k stars 3.88k forks source link

Bug (regression) : new-win-policy event not always thrown on popup opening in iframe #2820

Open armoret opened 9 years ago

armoret commented 9 years ago

Hi Roger, I'm using the iframe object for embedding a web site. It's working pretty very well (thank you) but depending on how a popup is openin this web site, I can or can't get (and catch) the new-win-policy event (This has been tested with version 0.11.3. Windows 32 bits).

What is working:

What is not working:

For instance, the code below works well if you open it from a local file but doesn't it you use the web site it has been picked of. I don't really understand why because if you consider the html tag anf the javascript code, the popup is open with a standard window.open call.

To reproduce the issue:

This is the hosted nw iframe I'm using (see url inside):

      <iframe name="myIframe" id="myIframe" src="http://www.airfrance.fr/FR/en/local/home/home/HomePageAction.do" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" onLoad="isLoaded();" allowtransparency="false" nwdisable nwfaketop></iframe>

Obviously, I'm catching the new-win-policy on the window containing this frame.

I've put the screenshot with the image link you have to click on to open a new window.

And here is the extract of the link on the remote page and the associated javascript code :

<a class="cutout_lien" href="https://shopping.airfrance.com/boutique/fr/E-SHOPPING-GRAND-PUBLIC3/index.htm" onclick="javascript:af_open(this);return false;" rel="1[,]"><h2 class="cutout_titre">Nos coups de cœur<br>Air France Shopping</h2><img alt="Air France Shopping" src="http://www.airfrance.fr/common/image/visuels_detoures/shopping.png" height="115" width="230"></a>

function af_open(elem){
 var t = elem.title || elem.name || '';
 var a = elem.href || elem.alt;
 var p = elem.rel || false;
 var m = "0";
 var l = 800;
 var h = 600;
 if(a==document.location.href){return false;}
 if(p){
    //on recupere la largeur et la hauteur
    var r = p.match(/^\s?([0-2])\s?\[\s?([0-9]*)\s?,\s?([0-9]*)\s?\]/g);
    m = RegExp.$1.toString();
    l = RegExp.$2.toString();
    h = RegExp.$3.toString();
 }
 if(m.match(/2/)){
        if(l.length==0 && h.length==0) {
            GB_showResize(t,a);//Fonction GreyBox (popin auto resize)
        } else {
            GB_showCenter(t,a,l,h);//Fonction GreyBox (popin taille fixe)
        }
 } else if(m.match(/1/)){
            window.open(a,t);
 } else {
            document.location = a;
 }
 return false;
}

screenshot_af

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

tommoor commented 9 years ago

You marked this as a regression, it would be useful to know which previous version it worked correctly in

armoret commented 9 years ago

Hum, you're right : I did not noticed this case before but it doesn't mean it was running correctly in previous releases because I did not check the pop-up windows opening in all the sites I've tested. I've changed the title of this post and will try to test again with the older releases I kept.

armoret commented 9 years ago

Hello to all, I confirm it's really a regression. I have tested the same code (see extract below) with an older version (0.9.2 win32) on the same web site and it was working well (in other words, the function was well called when opening a popup window clicking on one link).

I hope you will be able to fix it !

Thanks.

         // ------------------------  
        // Listen to the open event
        // ------------------------
        win.on('new-win-policy', function(frame, url, policy) {
            console.log('new-win-policy event on ' + frame);

            // To ignore:
            policy.ignore();

            // Open new child window, url is passed in a global variable
            console.log('Opening url in new window:' + url);
            global.url = url;
            var new_win = gui.Window.open('browser.html', {
                "show": true,
                "toolbar": false,
                "icon": "icon.png",
                "frame": true,
                "focus": true,
                "position": "center",
                "width": 1024,
                "height": 768,
                "min_width": 640,
                "min_height": 480
            });
        });
semmel commented 8 years ago

See #1519 new-win-policy event does not fire for not-node (normal) popup windows - this is not fixed in nwjs 0.16.0. (For node frames everything is fine.)

The event is not published on nw popup windows for target = '_blank' links.

Simple to reproduce from the developer tools:

nw.Window.open("http://www.example.com", {id : "example.com"},
(nwPopup) => nwPopup.on('loaded', () => {
    nwPopup.window.document.body.innerHTML = '<a href="https://www.google.de" target="_blank">Go to Google</a>';
    nwPopup.on('new-win-policy', console.log.bind(console, "popup window"));
})
);

03.08.2016 Updated the comment, that the bug concerns just non-node frames.

bsparks commented 7 years ago

I believe that this is happening when loading a chrome app. The chrome packaged apps do not seem to have a node context. Any idea on a fix or suggested work around?

rogerwang commented 7 years ago

You can give it Node context by adding "node" permission to manifest.json

On Nov 15, 2017 7:21 AM, "Ben Sparks" notifications@github.com wrote:

I believe that this is happening when loading a chrome app. The chrome packaged apps do not seem to have a node context. Any idea on a fix or suggested work around?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nwjs/nw.js/issues/2820#issuecomment-344433311, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKGGdgK43Br3Qnlac-8ELMYVV1Pw9GNks5s2iBdgaJpZM4DJipv .

bsparks commented 7 years ago

hmm, well I add "node" to permissions array in the manifest.json and then the app will no longer load. the exe gets added to the task manager (windows) but it no longer opens the packaged app window. there are no errors or any info as to why.