From f638f84185938c74a47f5691e8d7c5e1d4dca07c Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Fri, 15 Nov 2024 16:17:10 +0000 Subject: [PATCH] LibWeb: Make default document readiness be "complete" This is required by mini Cloudflare invisible challenges, as it will only run if the readyState is not "loading". If it is "loading", then it waits for readystatechange to check that it's not "loading" anymore. Initial about:blank iframes do not go through the full navigation and thus don't go through HTMLParser::the_end, which sets the ready state to something other than "loading". Therefore, the challenge would never run, as readyState would never change. Seen on https://discord.com/login --- Libraries/LibWeb/DOM/Document.h | 8 +++++++- .../document-readyState-is-initially-complete.txt | 5 +++++ .../LibWeb/Text/input/HTML/Window-postMessage.html | 14 ++------------ .../document-readyState-is-initially-complete.html | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/document-readyState-is-initially-complete.txt create mode 100644 Tests/LibWeb/Text/input/HTML/document-readyState-is-initially-complete.html diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index c8a882e1003..3c11a21b209 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -823,7 +823,13 @@ private: GC::Ptr m_associated_inert_template_document; GC::Ptr m_appropriate_template_contents_owner_document; - HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading }; + // https://html.spec.whatwg.org/multipage/dom.html#current-document-readiness + // Each Document has a current document readiness, a string, initially "complete". + // Spec Note: For Document objects created via the create and initialize a Document object algorithm, this will be + // immediately reset to "loading" before any script can observe the value of document.readyState. + // This default applies to other cases such as initial about:blank Documents or Documents without a + // browsing context. + HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Complete }; String m_content_type { "application/xml"_string }; Optional m_pragma_set_default_language; Optional m_encoding; diff --git a/Tests/LibWeb/Text/expected/HTML/document-readyState-is-initially-complete.txt b/Tests/LibWeb/Text/expected/HTML/document-readyState-is-initially-complete.txt new file mode 100644 index 00000000000..1475ac05792 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/document-readyState-is-initially-complete.txt @@ -0,0 +1,5 @@ +readyState of 'new Document()' should be 'complete': 'complete' +readyState of 'document.implementation.createHTMLDocument()' should be 'complete': 'complete' +readyState of 'document.implementation.createDocument()' should be 'complete': 'complete' +FIXME: readyState of 'new DOMParser().parseFromString('', 'text/html')' should be 'complete': 'interactive' +readyState of 'iframe.contentDocument' of initial about:blank iframe should be 'complete': 'complete' diff --git a/Tests/LibWeb/Text/input/HTML/Window-postMessage.html b/Tests/LibWeb/Text/input/HTML/Window-postMessage.html index 153eaa0952e..ec8f9608d6d 100644 --- a/Tests/LibWeb/Text/input/HTML/Window-postMessage.html +++ b/Tests/LibWeb/Text/input/HTML/Window-postMessage.html @@ -127,21 +127,11 @@ globalThis.doneCallback = done; const blobIframeLoadPromise = new Promise(resolve => { - if (blobIframe.contentDocument.readyState === "complete") { - resolve(); - } - else { - blobIframe.onload = () => resolve(); - } + blobIframe.onload = () => resolve(); }); const srcdocIframeLoadPromise = new Promise(resolve => { - if (iframe.contentDocument.readyState === "complete") { - resolve() - } - else { - iframe.onload = () => resolve(); - } + iframe.onload = () => resolve(); }); Promise.all([blobIframeLoadPromise, srcdocIframeLoadPromise]).then(() => { diff --git a/Tests/LibWeb/Text/input/HTML/document-readyState-is-initially-complete.html b/Tests/LibWeb/Text/input/HTML/document-readyState-is-initially-complete.html new file mode 100644 index 00000000000..3f5b996338a --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/document-readyState-is-initially-complete.html @@ -0,0 +1,14 @@ + + +