Penguin Zhou
Penguin Zhou

Reputation: 131

Chrome Extension popup size is incorrect sometimes

I wrote a chrome extension. I fixed the html width to be 400px.

It sometimes works fine but sometimes show up as a 25px width window which shows nothing.

I figured that everytime I inspect popup, the size is right. But when I open it normally, it has like 50% possibility to have an incorrect size.

BTW I have at the top of my HTML.

Upvotes: 4

Views: 1022

Answers (2)

Denis L
Denis L

Reputation: 3292

My current solution for this problem looks like this:

// Apply for Mac OS only
chrome.runtime.getPlatformInfo(info => {

    if (info.os === 'mac') {
        setTimeout(() => {
            // Increasing body size enforces the popup redrawing
            document.body.style.width = `${document.body.clientWidth + 1}px`;
        }, 250); // 250ms is enough to finish popup open animation
    }

});

Upvotes: 1

Penguin Zhou
Penguin Zhou

Reputation: 131

I changed add this to popup.

setTimeout(function(){
  document.getElementById('width-controller').style.width = '400px';
},200);

It almost never happens now. Still like 1 out of 15 would happen, but it is better than before.

Upvotes: 0

Related Questions