Verify that HTML parsing is supported in addition to DOMParser existence. This maybe wasn't as important before when DOMParser was used just as a fallback on Firefox, but now that DOMParser is the default choice, we need to be more accurate. PR Close #37783
This commit is contained in:

committed by
Andrew Kushnir

parent
7d270c235a
commit
12a71bc6bc
@ -120,15 +120,15 @@ class InertDocumentHelper implements InertBodyHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to determine whether the DOMParser exists in the global context.
|
||||
* The try-catch is because, on some browsers, trying to access this property
|
||||
* on window can actually throw an error.
|
||||
* We need to determine whether the DOMParser exists in the global context and
|
||||
* supports parsing HTML; HTML parsing support is not as wide as other formats, see
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/DOMParser#Browser_compatibility.
|
||||
*
|
||||
* @suppress {uselessCode}
|
||||
*/
|
||||
function isDOMParserAvailable() {
|
||||
export function isDOMParserAvailable() {
|
||||
try {
|
||||
return !!(window as any).DOMParser;
|
||||
return !!new (window as any).DOMParser().parseFromString('', 'text/html');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user