Fungovanie tejto stránky je z dôvodu údržby dočasne obmedzené. Ak článok nevyrieši váš problém a chcete položiť otázku, napíšte našej komunite podpory na Twitter @FirefoxSupport alebo Reddit /r/firefox.

Vyhľadajte odpoveď

Vyhnite sa podvodom s podporou. Nikdy vás nebudeme žiadať, aby ste zavolali alebo poslali SMS na telefónne číslo alebo zdieľali osobné informácie. Nahláste prosím podozrivú aktivitu použitím voľby “Nahlásiť zneužitie”.

Ďalšie informácie

Image fetch() fails when content-type charset is utf-8

  • 5 odpovedí
  • 1 má tento problém
  • 11 zobrazení
  • Posledná odpoveď od donmccurdy

more options

I'm using the `http-server` module from npm to serve a page locally. This module always includes the encoding=utf-8 header in content type, even for images. When requesting a JPG as follows:

<img src="puppy.png">

... it works fine. When trying to load the image via fetch():

  fetch( 'public/puppy.jpg' )
    .then( ( response ) => response.blob() )
    .then( ( blob ) => self.createImageBitmap( blob ) )
    .then( ( imageBitmap ) => {

      const canvasEl = document.querySelector( '#canvas' );
      const ctx = canvasEl.getContext( '2d' );
      ctx.drawImage( imageBitmap, 0, 0 );

    } )
    .catch( function ( error ) {

      console.warn( 'Error: ', error );

    } );

I see:

Error: DOMException [InvalidStateError: "An attempt was made to use an object that is not, or is no longer, usable"

In Chrome, both methods work. No other browsers currently support ImageBitmap.

I think the `http-server` module is technically incorrect in using encoding=utf-8, and when I switch to another serving module that doesn't, this error goes away. Nevertheless, i was surprised that Firefox was inconsistent, so here's a bug report. :)

I'm using the `http-server` module from npm to serve a page locally. This module always includes the encoding=utf-8 header in content type, even for images. When requesting a JPG as follows: &lt;img src="puppy.png"&gt; ... it works fine. When trying to load the image via fetch(): <pre><nowiki> fetch( 'public/puppy.jpg' ) .then( ( response ) => response.blob() ) .then( ( blob ) => self.createImageBitmap( blob ) ) .then( ( imageBitmap ) => { const canvasEl = document.querySelector( '#canvas' ); const ctx = canvasEl.getContext( '2d' ); ctx.drawImage( imageBitmap, 0, 0 ); } ) .catch( function ( error ) { console.warn( 'Error: ', error ); } ); </nowiki></pre> I see: Error: DOMException [InvalidStateError: "An attempt was made to use an object that is not, or is no longer, usable" In Chrome, both methods work. No other browsers currently support ImageBitmap. I think the `http-server` module is technically incorrect in using encoding=utf-8, and when I switch to another serving module that doesn't, this error goes away. Nevertheless, i was surprised that Firefox was inconsistent, so here's a bug report. :)

Upravil(a) cor-el dňa

Všetky odpovede (5)

more options

Oops. The line below "When requesting a JPG as follows:" should have been HTML showing an "img" tag with a "src="public/puppy.png"" attribute. That got stripped.

more options

What content-type is being sent by the server? I would think image/png would cause Firefox to ignore a character encoding header.

You should be able to confirm using the Network Monitor.

https://developer.mozilla.org/docs/Tools/Network_Monitor

more options

Everything works when the server sends "image/jpeg", but not with "image/jpeg; charset=utf-8". Full response headers attached, both for my working and broken server. The broken server is the one beginning with "server: ecstatic".

Also plausible that it's one of the other headers, but charset looked like the probable culprit.

more options

Do you want to file a bug?

https://bugzilla.mozilla.org/

more options