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 Parsing errors are not shown to the user #5

Closed
SamHasler opened this issue Sep 3, 2015 · 20 comments
Closed

CSS Parsing errors are not shown to the user #5

SamHasler opened this issue Sep 3, 2015 · 20 comments

Comments

@SamHasler
Copy link

I get the Unable to load stylesheet undefined with some third party css that uses an @page rule.

The parsing error is an issue with the parser library you're using (NV/CSSOM#5) but not showing the user that there was an error with the parsing is non-helpful.

To be able to see where the error was I edited rasterizeHTML.allinone.js to use the following code:

  c.loadAndInlineCssLinks=function(a,b){
    var c=r(a)
      , e=[];
    console.log("filtered links",c);
    return d.all(c.map(function(a){
      console.log("CSS",a);
      return (q(a,b)
                  .then(
                      function(b){
                        o(a,b.content+"\n")
                                  ,e=e.concat(b.errors)
                      }
                    ,function(ee){
                      console.log("CSS ERROR", [a,ee]);
                      e.push({resourceType:"stylesheet",url:ee.url,msg:"Unable to load stylesheet "+ (ee.url ||a.getAttribute('href')) +" -- "+ee})
                    })
             )}
@cburgmer
Copy link
Owner

cburgmer commented Sep 3, 2015

Thanks for digging into the issue.

The reason NV/CSSOM is currently used, is a bug in Chrome (https://code.google.com/p/chromium/issues/detail?id=161644). This might or might not have been fixed.
Also see mention here: https://github.com/cburgmer/rasterizeHTML.js/wiki/Browser-issues#chrome

In case you don't need the respective feature, or target other browsers, you should be able to take out CSSOM of the package, and the code will fallback to the browser's own CSSOM implementation.

@SamHasler
Copy link
Author

Thanks for the tip on disabling CSSOM. I hadn't realized it would work without it. It actually fixes a rendering issue I had with some gnarly relative positioning, although only in chrome canary; not Chrome stable or Firefox developer edition.

@cburgmer
Copy link
Owner

cburgmer commented Sep 5, 2015

I'd like to continue ship CSSOM in the allinone build by default, as the Chrome bug fails a basic feature here. Let's hope CSSOM catches up with the newest CSS features.

@cburgmer
Copy link
Owner

cburgmer commented Sep 5, 2015

But yes, we should make the error reporting better here. The parsing error should be reported.

@cburgmer
Copy link
Owner

cburgmer commented Sep 5, 2015

I am trying to make the method fail, but can't. Do you have a short example?

I believe it is one of the steps in https://github.com/cburgmer/inlineresources/blob/master/src/inline.js#L118 that is failing.

@SamHasler
Copy link
Author

From memory:

  @media print {
     @page {
        // rules
      }
  }

Also, HTML parsing errors. E.g.: <namespace:customtag></ namespace:customtag>

(I cut & pasted HTML into a test where our server framework had failed to render a tag.)

I'll check on Monday if there was anything else I has to fix in my code to get the test to run.

@cburgmer
Copy link
Owner

cburgmer commented Sep 6, 2015

The HTML I can directly reproduce. The @page rule, I cannot, using rasterizeHTML.js/examples/index.html (and the dev console open). Do send me a full example once you have it.

As for the HTML tag issue, I don't have an initial guess where this is happening - it is interesting to see though that there's no direct stack trace.

@SamHasler
Copy link
Author

I can tell you where the HTML issue is on Monday when I'm back to work.
Same for the @page example.
On Sep 6, 2015 4:12 AM, "Christoph Burgmer" [email protected]
wrote:

The HTML I can directly reproduce. The @page https://github.com/page
rule, I cannot, using rasterizeHTML.js/examples/index.html (and the dev
console open). Do send me a full example once you have it.

As for the HTML tag issue, I don't have an initial guess where this is
happening - it is interesting to see though that there's no direct stack
trace.


Reply to this email directly or view it on GitHub
#5 (comment)
.

@SamHasler
Copy link
Author

looks like the CSS issue may have been relative paths to non-existant images in backround urls. I think @page was a red-herring, I have a test page with it in rendering fine. I'll try and make a reduced testcase tomorrow.

@SamHasler
Copy link
Author

the html errors are in rasterizeHTML.js isParseError

@SamHasler
Copy link
Author

I'd forgot to turn CSSOM back on. Here's a testcase:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>@media print { body { @page{} } }</title>
  <style>
    @media print {
      @page {
        body {}
      }
    }
  </style>
</head>
<body>
  @page was parsed.
  (CSSOM won't parse @page, Chrome will)
</body>
</html>

@cburgmer
Copy link
Owner

cburgmer commented Sep 8, 2015

On the HTML error in rasterizeHTML: This is a limitation, which I've actually documented in the past (should've thought of that earlier). See the last point under https://github.com/cburgmer/rasterizeHTML.js/wiki/Limitations.

The issue is simple: To render any HTML, it needs to be rewritten as valid XML, but the XMLSerializer does not know what to do with those tags, as they are invalid XML as long as now namespace is declared (which could be a temporary work around for you).

If you have an idea how to fix this or a certain expectation on what it should do instead, do open a ticker with rasterizeHTML and we can discuss there.

@cburgmer
Copy link
Owner

cburgmer commented Sep 8, 2015

Thanks for the test case. I was testing in the wrong browser, and so cssom was never loaded.

For me the error is thrown and visible in the console, and it is unclear to me, why the error is not captured in the promise chain, and properly reported.

However, even if this reporting issue got fixed, we are talking about a non-standard behaviour of the CSS parsing drop-in, as the default behaviour of the browser's seems to be to ignore any invalid CSS and keep on parsing.

The proper solution to this problem to me seems to make Chrome fix the original issue the workaround was implemented for.

@SamHasler
Copy link
Author

I was trying to create a testcase for our app's currect CSS and so I just
linked straight to the head copy checked out of svn and pasted in a static
copy of a page into the body. Then when I ran the regression test nothing
happened. It took a long while to figure out it was a CSS parsing issue and
longer to work out where in the code to add a console.log to see the error.

Someone else might have concluded that csscritic didn't work and given up
(e.g. me some months ago).

If the errors are reported it allows users to fix their code and get a
working test that's useful to them.
On Sep 8, 2015 3:08 PM, "Christoph Burgmer" [email protected]
wrote:

Thanks for the test case. I was testing in the wrong browser, and so cssom
was never loaded.

For me the error is thrown and visible in the console, and it is unclear
to me, why the error is not captured in the promise chain, and properly
reported.

However, even if this reporting issue got fixed, we are talking about a
non-standard behaviour of the CSS parsing drop-in, as the default behaviour
of the browser's seems to be to ignore any invalid CSS and keep on parsing.

The proper solution to this problem to me seems to make Chrome fix the
original issue the workaround was implemented for.


Reply to this email directly or view it on GitHub
#5 (comment)
.

@cburgmer
Copy link
Owner

cburgmer commented Sep 9, 2015

I think it should be feasible to catch the error, and record properly.

The only issue is though, that it's hard to log the point of the actual failure. I feel JavaScript's error reporting is not making it easy to handle such things across browsers well.

I might find time to look into this, but I'll be happy for any help on this :)

@SamHasler
Copy link
Author

I've got my css working for now but I'll probably come across it again soon. I'll make a PR if I can work out a way to get the details of the error.

@SamHasler
Copy link
Author

I've raised a separate issue for the HTML errors: cburgmer/csscritic#65

@cburgmer
Copy link
Owner

cburgmer commented Oct 3, 2015

Trying to summarise this ticket:

  1. CSSOM in Chrome fails at @page rules.
  2. Those errors are not properly reported.
  3. HTML errors are not properly reported.

I'd like to tackle

  1. via issue Dispose of CSSOM as a dependency  #7
  2. will go away when Dispose of CSSOM as a dependency  #7 is solved
  3. via issue rasterizeHTML.js DOMParser errors are not reported to the user csscritic#65

Do you think it is OK to close this issue?

@SamHasler
Copy link
Author

Yep. That sums it up. Ok to close. Good that chrome team picked up that bug.
On Oct 3, 2015 6:41 AM, "Christoph Burgmer" [email protected]
wrote:

Trying to summarise this ticket:

  1. CSSOM in Chrome fails at @page rules.
  2. Those errors are not properly reported.
  3. HTML errors are not properly reported.

I'd like to tackle

  1. via issue Dispose of CSSOM as a dependency  #7 Dispose of CSSOM as a dependency  #7
  2. will go away when Dispose of CSSOM as a dependency  #7
    Dispose of CSSOM as a dependency  #7 is solved
  3. via issue rasterizeHTML.js DOMParser errors are not reported to the user csscritic#65
    rasterizeHTML.js DOMParser errors are not reported to the user csscritic#65

Do you think it is OK to close this issue?


Reply to this email directly or view it on GitHub
#5 (comment)
.

@cburgmer
Copy link
Owner

cburgmer commented Oct 3, 2015

Thanks for prodding the Chrome guys. Helped a lot :)

@cburgmer cburgmer closed this as completed Oct 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants