Ademking / BetterViewer

a replacement for the image viewing mode built into Firefox and Chrome-based web browsers.
MIT License
247 stars 19 forks source link

Can you add support for the Data URI Scheme for "Open image in new tab"? #43

Open JoeFisherman2000 opened 1 year ago

JoeFisherman2000 commented 1 year ago

I really like this extension!

I see on your welcome page that the sample jpg is displayed within an img HTML element and I assume you are working off the src attribute to determine if you can display "Open image in new tab" in your context menu.

<img id="demo-img" class="pulsate-fwd shadow cursor-pointer lg:w-2/6 md:w-3/6 w-4/6 object-cover object-center rounded" alt="hero" src="cat_dog.jpg">

It would be great if you could add support for the Data URI Scheme and allow that to also display "Open image in new tab" in your context window when one is encountered.

<img id="myImage" alt="Image Display" src="data:image/png;base64,<base64EncodedString>">

Here is a sample with a tiny Base64 Encoded String included:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

Where image/png is the Media Type. Other valid image Media Types include: image/avif, image/jpeg and image/svg+xml.

Not sure if the extension currently supports PNG images but I know it supports JPG so if no other media types if you could support image/jpeg within the Data URI Schema that would really be great!

Thank you for considering this enhancement!

Metacor commented 1 year ago

BetterViewer doesn't actually add any context menus, "Open image in new tab" is default browser functionality. The way the extension works is by adding a listener to chrome.webRequest, and then checking the 'content-type' in the Response Headers to see if it is has the MIME type of "Image/", all image types should work by default, (although /svg+xml is currently broken, the extension recognizes it but gives out errors) [examples of /avif and /png]*

As for adding support for data: pages, I don't think they respond to webRequests, so it might require a rewrite of how the extension activates, I could be missing something obvious though.