How I did it
The extension is very easy, it executes a GET request to the xkcd website, gets the content of the index page and returns it. What I used to do, for a matter of simplicity, was getting the content, paste it in an hidden div, get the image of the comic of the day (through a getElementById call) and put it in a visible div.
What one would expect is that the Google Chrome popup page of the extension notice the change of content and resize itself to fit the new content. But this doesn't happen. The popup page remains as small as it can get without styles, or of a fixed with/height if specified in the css file. I didn't wanted to have a fixed width/height as comics usually have not a fixed size (sometimes they are as small as a strip, sometimes they are quite big).
var width = document.getElementById("comic").offsetWidth + 10; var height = document.getElementById("comic").offsetHeight + 10; //[...] document.body.style.width = ""+width; document.body.style.height = ""+height; document.getElementsByTagName("html").style.width = ""+width; document.getElementsByTagName("html").style.height = ""+height;
(notice that I get the width and the height of the image and add a small offset to make it visually finer). The fact is that this approach wasn't working either. When opening the extension, one would see it flicker: first a frame of the correct size, and then a resize to the default 10 by 10 pixel frame.
The solution was quite simple, but without somebody mentioning it on StackOverflow I would be still stuck. The fact is that the popup of the Chrome Extensions don't resize if there is a hidden element in the HTML tree. That is, basically the whole page I was hiding was preventing me to resize the popup frame. So the solution is:
document.getElementById("hiddenDiv").innerHTML = "";
And that solved every problem. The frame now is the correct size and I can read every two/three days the new xkcd comic.