kubuzetto / behind

behind! addon source code repository
https://addons.mozilla.org/en-US/firefox/addon/behind/
Mozilla Public License 2.0
89 stars 3 forks source link

Feature suggestion: displaying image sizes #15

Closed lkintact closed 3 years ago

lkintact commented 3 years ago

Thank you for implementing #13. What would you say about adding the file size to the image description, too?

Behind! version: 0.2.15, Browser: Firefox 88.0.1.

jscher2000 commented 3 years ago

Maybe something like this around line 67 of inline.js:

if (window.performance){
  var imgp = performance.getEntriesByName(im.src);
  if (imgp[0] && imgp[0].decodedBodySize > 0){
    spn.innerText += ' (' + imgp[0].decodedBodySize.toLocaleString() + ' bytes)';
  }
}

Like so:

behind-image-size-demo

kubuzetto commented 3 years ago

Thank you for the bug report! I wanted to see the feasibility of this before responding to the issue, and I ran a few tests with the Performance API (thank you very much for the suggestion @jscher2000).

Unfortunately, there is a recurring case where the getEntriesByName call returns an empty array. Strangely, refreshing the inline page returns the proper results.

At first I thought it was a race condition, maybe I was requesting the data before it was set. Adding a PerformanceObserver in the mix did not help. I periodically polled the whole entry list with getEntries instead, and saw that the relevant PerformanceResourceTiming entries are never registered.

For now, I can't get it to work reliably. I will keep looking into this.

kubuzetto commented 3 years ago

(If anybody else is interested in looking into this, you can replicate this problem with the main Google logo in the Google main page)

jscher2000 commented 3 years ago

Hmm, bummer. I have some elaborate code to bypass the cache, which might be why I can get the value.

That might be more trouble than it's worth.

kubuzetto commented 3 years ago

Closing this issue, since I was unable to find a reliable method for this.