Den här webbplatsen har begränsad funktionalitet medan vi utför underhåll för att förbättra din upplevelse. Om en artikel inte löser ditt problem och du vill ställa en fråga har vi vår gemenskap som väntar på att hjälpa dig på @FirefoxSupport på Twitter, /r/firefox på Reddit.

Sök i support

Akta dig för supportbedrägerier: Vi kommer aldrig att be dig att ringa eller skicka ett sms till ett telefonnummer eller dela personlig information. Rapportera misstänkt aktivitet med alternativet "Rapportera missbruk".

Läs mer

Firefox 93 on linux returns type of image/png when querying for webp

more options

Hmm, not sure mozilla support is the right place, and I can't get 'matrix' working at all, since irc is no longer supported.

I want to use javascript to detect whether the browser has webp support. This is the recommended javascript technique... ``` function canUseWebP() {

   var elem = document.createElement('canvas');    if (!!(elem.getContext && elem.getContext('2d'))) {
       // was able or not to get WebP representation
       return elem.toDataURL('image/webp').indexOf('data:image/webp') == 0;
   }    // very old browser like IE 8, canvas not supported
   return false;

} ``` but elem.toDataURL('image/webp') returns a binary blob that has 'image/png' as a header.

Why does Firefox return 'image/png' when it should return 'image/webp'?

Hmm, not sure mozilla support is the right place, and I can't get 'matrix' working at all, since irc is no longer supported. I want to use javascript to detect whether the browser has webp support. This is the recommended javascript technique... ``` function canUseWebP() { var elem = document.createElement('canvas'); if (!!(elem.getContext && elem.getContext('2d'))) { // was able or not to get WebP representation return elem.toDataURL('image/webp').indexOf('data:image/webp') == 0; } // very old browser like IE 8, canvas not supported return false; } ``` but elem.toDataURL('image/webp') returns a binary blob that has 'image/png' as a header. Why does Firefox return 'image/png' when it should return 'image/webp'?

Alla svar (1)

more options

Judging from the following table, it looks like Firefox won't support 'image/webp' as a parameter of toDataURL() until the next release, Firefox 96:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL#browser_compatibility

Why do you need to test for WebP support using a script?