Currently developing a Chrome packaged app. I have implemented a fullscreen feature. Long story short:
If the app was quitted/closed while it was fullscreen, the app window will launch in fullscreen mode but the content is not fullscreen because you cannot go fullscreen without user interaction!
How I go fullscreen (content-script)
document.addEventListener("webkitfullscreenchange", function () {
if(document.webkitIsFullScreen === true) {
document.querySelector('.active webview').contentWindow.postMessage('fullscreen, enter', 'http://'+viewer.app.networkHost+':'+viewer.app.networkPort+'/*');
document.body.webkitRequestFullscreen();
$("#presenter, #slide-container .owl-item").addClass('fullscreen tenTwenty');
$("#viewer-container, #slide-container").addClass('fullscreen thirteenSix');
$("#scroll-left, #scroll-right, #scroll-top").addClass('scroll-fullscreen');
$('.fullscreen').width(screen.width);
$('.fullscreen').height(screen.height);
$('#slide-container').trigger('refresh.owl.carousel');
} else {
console.log('not fullscreen');
document.webkitCancelFullScreen();
document.querySelector('.active webview').contentWindow.postMessage('fullscreen, exit', 'http://'+viewer.app.networkHost+':'+viewer.app.networkPort+'/*');
$('.tenTwenty').width(1024); $('.tenTwenty').height(768);
$('.thirteenSix').width(1366); $('.thirteenSix').height(768);
$("#presenter, #viewer-container, #slide-container, #slide-container .owl-item").removeClass('fullscreen tenTwenty thirteenSix');
$("#scroll-left, #scroll-right, #scroll-top").removeClass('scroll-fullscreen');
$('#slide-container').trigger('refresh.owl.carousel');
}
viewer.showControls();
}, false);
Creating the window
openViewer: function(pres_id) {
var self = this;
self.current_presentation_id = pres_id;
chrome.app.window.create(
'view/viewer.html',
{
id: 'presentation-viewer-'+pres_id,
outerBounds: { width: 1024, height: 768 },
"resizable": false,
}, function(createdWindow) {
// Run animation for first slide
window.setTimeout(function() {
createdWindow.contentWindow.window.viewer.firstSlideAnimation();
createdWindow.contentWindow.window.viewer.toggleNavigation();
}, 3500);
if(createdWindow.isFullscreen() === true) {
window.setTimeout(function() {
//It is fullscreen I need to request fullscreen but it will not allow me
}, 2500);
}
createdWindow.onClosed.addListener(function() {
//Close all sockets on close
chrome.sockets.tcp.getSockets(function(s) {
$(s).each(function() {
chrome.sockets.tcp.disconnect(this.socketId);
chrome.sockets.tcp.close(this.socketId);
});
});
/*
Somehow here, I need to exit fullscreen maybe? This does not work of course
createdWindow.contentWindow.document.webkitCancelFullScreen();
*/
});
//Get document
console.log(createdWindow.contentWindow.window.document);
//createdWindow.contentWindow.window;
}
);
}
My question
Can I block the app from launching in fullscreen, reset the status when closed or even force fullscreen by webkitRequestFullscreen() ? Any of these will resolve my problem.