chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create('window.html',
        {
            'bounds': {
                'width': 800,
                'height': 680
            },
            id: 'whatsapp'
        },
        onWindowCreated
    );
});

function onWindowCreated(appWin) {

    appWin.contentWindow.addEventListener('load', function(){

        var webview = appWin.contentWindow.document.querySelector('webview');

        // Resize the webview when the window resizes.
        appWin.onBoundsChanged.addListener(function(){onBoundsChanged(appWin)});


        // Initialize the webview size once on launch.
        setTimeout(function() {
            onBoundsChanged(appWin);
        }, 0);

        ////Interval to fix the white window on startup
        var interval = setInterval(function() {
            onBoundsChanged(appWin);
            webview.executeScript(
                {
                    file: 'hide-notification-request.js'
                }
            )
        }, 100);

        //Cancel the hacky interval after a minute
        setTimeout(function() {
            clearInterval(interval);

        }, 60000);
    });

    appWin.contentWindow.addEventListener('message', function(e) {
        if (!appWin.contentWindow.document.hasFocus()) {
            appWin.drawAttention();
        } else {
            appWin.clearAttention();
        }
    });

    //chrome.browserAction.setBadgeText({text: "10+"})


}

function onBoundsChanged(appWin) {
    var webview = appWin.contentWindow.document.querySelector('webview');

    var bounds = appWin.getBounds();
    var variance = Math.round(Math.random() * 10);
    webview.style.height = bounds.height  + 'px';
    webview.style.width = bounds.width + '.0' + variance + 'px';
}
@@ -814,312 +814,427 @@
 l = 
-setInterval(function() %7B%0A            onBoundsChanged(appWin);%0A            webview.executeScript(%0A                %7B%0A                    file: 'hide-notification-request.js'%0A                %7D%0A            )%0A        %7D, 100);%0A%0A        //Cancel the hacky interval aft
+createFixWhiteScreenInterval(100);%0A%0A        //Cancel the hacky interval after a minute%0A        setTimeout(function() %7B%0A            clearInterval(interval);%0A%0A            //We still fix the issue every 3 seconds just in case%0A            //Helpful for when someone takes too much time doing the QR code.%0A            //A more elegant fix for this would be doing jquery-livequ
 er
+y
  a
- minute%0A        setTimeout(function() %7B
+nd listen for when the actual page is drawn
 %0A   
@@ -1235,36 +1235,51 @@
 wn%0A            c
-lear
+reateFixWhiteScreen
 Interval(interva
@@ -1267,36 +1267,31 @@
 eenInterval(
-interval
+3000
 );%0A
-%0A
         %7D, 6
@@ -1542,65 +1542,171 @@
 %7D);%0A
-%0A    //chrome.browserAction.setBadgeText(%7Btext: %2210+%22%7D)%0A%0A
+%7D%0A%0Afunction createFixWhiteScreenInterval(interval) %7B%0A    var interval = setInterval(function() %7B%0A        onBoundsChanged(appWin);%0A    %7D, 100);%0A    return interval;
 %0A%7D%0A%0A

Fix for when a person takes too much time doing the QR code