Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS loaded as incorrect charset unless explicitly declared #10060

Open
edent opened this issue Dec 1, 2019 · 35 comments
Open

CSS loaded as incorrect charset unless explicitly declared #10060

edent opened this issue Dec 1, 2019 · 35 comments

Comments

@edent
Copy link

edent commented Dec 1, 2019

Provide the steps to reproduce

  1. Run LH on https://shkspr.mobi/blog/
  2. When the page reloads, the emoji incorrectly renders as âœ.

Before LH

Correct Rendering

After LH

After Lightspeed

What is the current behavior?

Why this occurs:

  • My style.css contains content: "✍";
  • It is served as Content-Type: text/css; with no charset.
  • When the devtools reloads the page after Lighthouse runs, it corrupts the text - I think into Windows-1252
  • If I add @charset "UTF-8"; at the start of the CSS file, it renders correctly after Lighthouse runs.

What is the expected behavior?

The CSS spec says, if a text encoding can't be determined, assume UTF-8.

(I am unable to change the server to serve Content-Type: text/css; charset=utf-8)

Environment Information

  • Lighthouse version: Whatever ships with Chromium 78
  • Chrome version: Version 78.0.3904.108 (Official Build) snap (64-bit)
  • Operating System: Ubuntu

Related issues

@connorjclark
Copy link
Collaborator

On Mac and can't reproduce. Perhaps it is just Linux.

@edent
Copy link
Author

edent commented Dec 1, 2019

I've reproduced it on Mac. Mojave. Chrome Version 78.0.3904.108 (Official Build) (64-bit)

Screenshot 2019-12-01 at 18 11 56

@dwm
Copy link

dwm commented Dec 1, 2019

I successfully reproduced this on Windows with my default configuration:

disabled slowdown
desktop mode
OS: Windows 10
Chrome: Version 78.0.3904.108 (Official Build) (64-bit)

See image: reproduced

My default configuration includes the HTTPS Everywhere extension (https://chrome.google.com/webstore/detail/https-everywhere/gcbommkclmclpchllfjekcdonpmejbdp). When I direct HTTPS Everywhere to stop operating and re-run the test, this misbehaviour does not occur.

@bearpig
Copy link

bearpig commented Dec 2, 2019

On Mac (10.14.6) & Chrome (78.0.3904.108) - have reproduced.

See image.
Screenshot 2019-12-02 at 13 51 01

edit - although this doesn't happen in Incognito Mode, and I do run a fair few chrome extensions normally, so might be a caching conflict somewhere?

@connorjclark
Copy link
Collaborator

@edent can you confirm @bearpig's extension theory by trying this in Incognito?

@edent edent closed this as completed Jan 9, 2020
@edent
Copy link
Author

edent commented Jan 9, 2020

Reproduced in 79 on Mac in incognito mode. Reproducible example at http://shkspr.mobi/test/test.html

@edent edent reopened this Jan 9, 2020
@patrickhulce
Copy link
Collaborator

@edent I'm not able to reproduce this behavior in a clean Chrome profile and Incognito mode on m79. Is it possible you still have some Chrome extensions running in Incognito mode?

@edent
Copy link
Author

edent commented Jan 9, 2020

Just installed a fresh Chrome on Linux. No extensions. Still fails.
google

Settings are Desktop, Accessibility, No Throttling, Clear Storage.

Chrome Version 79.0.3945.117 (Official Build) (64-bit)
Generated by Lighthouse 5.5.0

The only thing which could be different is that my language settings are English UK / en_gb

@jpwsutton
Copy link

Hi, I have the same issue on macos
Chrome Version 79.0.3945.88 (Official Build) (64-bit)
Lighthouse 5.5.0

Screenshot 2020-01-09 at 21 37 04

@edent
Copy link
Author

edent commented Jan 10, 2020

Here's a completely fresh Canary build on OSX. No extensions loaded.
Screenshot 2020-01-10 at 10 01 15

@patrickhulce
Copy link
Collaborator

Aha! Canary + Desktop did the trick thanks folks I'm able to reproduce now on macOS.

@connorjclark
Copy link
Collaborator

Canary 81.0.4026.0, OSX. Still can't repro. @patrickhulce is it fixed for you?

@edent
Copy link
Author

edent commented Jan 13, 2020

Still an issue on 4026.
Screenshot 2020-01-13 at 19 03 27

Fresh install. No plugins. UK / EN_GB language. Accessibility Desktop Audit.

@patrickhulce
Copy link
Collaborator

Confirmed still an issue on 81.0.4026.0 for me as well on macOS.

@connorjclark you're running with exactly these settings, right?
image

@connorjclark
Copy link
Collaborator

yes

image

what rendered font does your system use for the element w/ the hand emoji?

@patrickhulce
Copy link
Collaborator

not that :)
image

also worth noting that simply refreshing the page fixes the issue and uses Apple Color Emoji font again

@connorjclark
Copy link
Collaborator

i dunno then. Can't repro so this is all you atm :)

@patrickhulce
Copy link
Collaborator

Feels eerily similar to #10067 , P1.5 because whatever's going on with DevTools audits deserves a look.

@edent
Copy link
Author

edent commented Dec 20, 2020

We've passed the 1 year anniversary of this bug - and it is still a problem. Could someone please help me fix it?

Screencast.from.20-12-20.22.53.16.mp4

To reproduce:

  • Visit https://shkspr.mobi/test/test.html
  • Use an incognito window with no extensions, on the latest version of Chrome
  • Run a Lighthouse report as a Desktop device
  • You may need to be set to en_gb
  • Reproduced on Mac and Linux and Windows - see above

Minimum Viable Code:

HTML

<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<link rel="stylesheet" href="test.css">
 </head>
 <body>
 	<hr class="emoji"/>
 </body>
 </html>

CSS

.emoji:after {
    content: "✍";
    font-size: 2em;
    display: inline-block;
    position: relative;
    top: -0.33em;
}

@connorjclark
Copy link
Collaborator

connorjclark commented Dec 21, 2020

Noticed that the CSS doesn't show up in the Network tab after the LH run. First clear the Network panel, then run LH, then go back to Network panel and you see:

image

(blocking the CSS resource on a normal page load doesn't create the same effect–in that case it's just a page with no text)

Also: this only happens if "Disable Cache" is not checked. That's the default in a new chrome profile, which is why Incognito repros so well. Also doesn't repro with just "Performance" checks (seems it only happens when LH does multiple passes?)

@patrickhulce
Copy link
Collaborator

Nice find @connorjclark , possibly

blockedUrlPatterns: ['*.css', '*.jpg', '*.jpeg', '*.png', '*.gif', '*.svg', '*.ttf', '*.woff', '*.woff2'],
leftover? I wonder if LH cleaned up its blocked patterns instead of just disconnecting it would fix it.

@connorjclark
Copy link
Collaborator

Big hunch: perhaps Chrome is correctly (as the spec says) assuming UTF-8 when it gets a CSS response w/ no charset, but when it saves to cache and reads from it later, makes no such assumption about encoding. This might be enough information to file a chromium bug–what do others think?

@connorjclark
Copy link
Collaborator

connorjclark commented Dec 21, 2020

@patrickhulce I don't see how that would matter–if the resource were blocked, the page would have no text (because text is only added via the CSS). It's an encoding issue, not a missing resource.

But I'll try to comment that out locally in DT.

@patrickhulce
Copy link
Collaborator

patrickhulce commented Dec 21, 2020

If the source of the issue is a subtle change in resource loading assumptions and one part of Chrome thinks this request should be blocked while another part doesn't actually block it, seems like there's at least a chance it's related.

The cache route also seems promising, if so, should be able to repro with a simple local server and no LH involved (which makes a far more compelling CRbug IMO :)).

@connorjclark
Copy link
Collaborator

But I'll try to comment that out locally in DT.

Still happens even if removing the blockedUrlPatterns.

Minimal settings for repro: do not check "Disable Cache", only check PWA category, desktop config.

@paulirish
Copy link
Member

The CSS is served by the memory cache in these "corrupted" cases.

At the protocol-level, we don't see a Network.requestWillBeSent (typically), which is why it doesn't show up in the Network panel. Normally, even memory-cache served items have one of these.

Also funny: the Network.requestServedFromCache event indicates it's served from memory cache, and it's emitted entirely separately from the .responseReceived payload which signals about 3 different caches.

image

@paulirish
Copy link
Member

A workaround is that we run cleanBrowserCaches at the end of our gathering, this'd clear the memory cache and ensure this subsequent load would refetch and be OK.

@connorjclark
Copy link
Collaborator

connorjclark commented Dec 21, 2020

I agree it must be serving from cache, but the protocol doesn't say that explicitly.

image

There's a "served from cache" event but that's from before Lighthouse ends, as far as I can tell. I highlighted the last request for the HTML document. No request follows for the CSS (cache or otherwise), according to the protocol.

@connorjclark
Copy link
Collaborator

connorjclark commented Dec 21, 2020

Oh, and loading normally w/ cache enabled and devtools open (refreshing, don't run LH), you can see the CSS served by "memory cache" but it never "corrupts" :/

@paulirish
Copy link
Member

paulirish commented Dec 21, 2020

I took a look at the data in chrome://net-export/ but nothing worthwhile there. Kinda makes sense to me, given that the memory cache lives in the renderer and net-layer is way out in the browser process.

@connorjclark connorjclark self-assigned this Mar 29, 2021
@sbenstewart
Copy link

Replicated the issue with the following setup.
OS - Windows 11 Home Single Language 21H2
Chrome - Version 96.0.4664.45 (Official Build) (64-bit)
Screenshot 2021-12-01 193136

And, this is the second anniversary of this bug!

@adamraine
Copy link
Member

I don't have a minified repro, but I was able to prevent the issue with changes in this branch:
https://github.com/GoogleChrome/lighthouse/compare/stop-charset-change

It looks like this changes too much with the page load, but reenabling full-page-screenshot will still produce the charset problem. I suspect it's an issue with the Page CDP domain messing with the cache or something.

@edent
Copy link
Author

edent commented Feb 25, 2023

Three years later and this bug is still present on Version 110.0.5481.96

Do you have a Patreon or something I can donate to in order to get this fixed?

@amirsarfarW
Copy link

Same issues happening here! :(

@amirsarfarW
Copy link

Three years later and this bug is still present on Version 110.0.5481.96

Do you have a Patreon or something I can donate to in order to get this fixed?

Did you find any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

12 participants