fix(core): do not trigger CSP alert/report in Firefox and Chrome (#36578) (#36578)
fix(core): do not trigger CSP alert/report in Firefox and Chrome (#36578) (#36578)

If [innerHTML] is used in a component and a Content-Security-Policy is set
that does not allow inline styles then Firefox and Chrome show the following
message:

> Content Security Policy: The page’s settings observed the loading of a
resource at self (“default-src”). A CSP report is being sent.

This message is caused because Angular is creating an inline style tag to
test for a browser bug that we use to decide what sanitization strategy to
use, which causes CSP violation errors if inline CSS is prohibited.

This test is no longer necessary, since the `DOMParser` is now safe to use
and the `style` based check is redundant.

In this fix, we default to using `DOMParser` if it is available and fall back
to `createHTMLDocument()` if needed. This is the approach used by DOMPurify
too.

The related unit tests in `html_sanitizer_spec.ts`, "should not allow
JavaScript execution when creating inert document" and "should not allow
JavaScript hidden in badly formed HTML to get through sanitization (Firefox
bug)", are left untouched to assert that the behavior hasn't changed in
those scenarios.

Fixes #25214.

PR Close #36578

gkalpak/angular,blesh/angular,gdi2290/angular,manekinekko/angular,gkalpak/angular,blesh/angular,blesh/angular,gdi2290/angular,IdeaBlade/angular,ocombe/angular,blesh/angular,IdeaBlade/angular,alxhub/angular,gkalpak/angular,angular/angular,blesh/angular,gdi2290/angular,gnomeontherun/angular,mgechev/angular,mgechev/angular,gkalpak/angular,brandonroberts/angular,JiaLiPassion/angular,manekinekko/angular,alxhub/angular,wKoza/angular,filipesilva/angular,filipesilva/angular,brandonroberts/angular,wKoza/angular,gdi2290/angular,manekinekko/angular,gnomeontherun/angular,angular-indonesia/angular,manekinekko/angular,filipesilva/angular,angular/angular,brandonroberts/angular,mgechev/angular,gdi2290/angular,IdeaBlade/angular,wKoza/angular,brandonroberts/angular,IdeaBlade/angular,ocombe/angular,brandonroberts/angular,shairez/angular,mgechev/angular,angular/angular,alxhub/angular,mgechev/angular,gnomeontherun/angular,ocombe/angular,angular-indonesia/angular,wKoza/angular,JiaLiPassion/angular,filipesilva/angular,wKoza/angular,shairez/angular,manekinekko/angular,angular/angular,brandonroberts/angular,filipesilva/angular,gdi2290/angular,ocombe/angular,angular-indonesia/angular,angular-indonesia/angular,gnomeontherun/angular,alxhub/angular,wKoza/angular,shairez/angular,ocombe/angular,JiaLiPassion/angular,manekinekko/angular,JiaLiPassion/angular,alxhub/angular,ocombe/angular,shairez/angular,shairez/angular,IdeaBlade/angular