belter icon indicating copy to clipboard operation
belter copied to clipboard

[Bug] Conflicting line of code in src/dom.js causing infinte loop. (waitForDocumentBody)

Open Cijin opened this issue 4 years ago • 2 comments

The function checks if the document body is present. If the document is not ready, it waits for the window to be ready and checks again if the document body is present. If the body is present, it returns the body. If not throws an error. This is the code:

 return waitForDocumentReady().then(() => {
            if (document.body) {
                return document.body;
            }

            throw new Error('Document ready but document.body not present');
        });

But, waitForDocumentReady calls isDocumentReady which in turn checks:

if (document.body && document.readyState === 'complete) return true`

That means the document cannot be ready without the body being ready. This causes an error while testing, when I mocked document.body = null. Also leads to throw being unreachable.

Cijin avatar Oct 28 '20 04:10 Cijin