-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Cannot read property 'body' of null
error when using .type()
in a contenteditable body element inside an iframe
#5930
Cannot read property 'body' of null
error when using .type()
in a contenteditable body element inside an iframe
#5930
Comments
I confirmed, this is a regression introduced in 3.5.0.
<!DOCTYPE html>
<html>
<body>
<iframe src="iframe.html" title="iframe Example 1"
width="400" height="300"></iframe>
</body>
</html>
<!DOCTYPE html>
<html>
<body contenteditable="true">
<p>foo bar</p>
</body>
</html>
it('test', () => {
cy.visit('index.html')
cy.get('iframe').then(($iframe) => {
const $body = $iframe.contents().find('body')
cy.wrap($body).find('p').type('test')
});
}) 3.4.13.5.0 |
Just a note that this affects CKEditor also, as it uses an |
Following this thread as it's affecting all my cypress tests that have iframes in them. |
Cannot read property 'body' of null
error when using .type()
in a contenteditable body element inside an iframe
Cannot update cypress version in my project because of that. |
@jennifer-shehane Any update? Please give us eta on the fix. Due to this we are stuck with 3.4.1 and we cant use the latest 18.04 container because of #6212. So its a circle of doom. |
Yes we are heavily affected by this and are stuck on a previous version. We really want to upgrade to 4.0 which has Firefox and Edge support. |
Ditto with all the above comments |
Hmm I think it would be related to this commit : 9b1f589#diff-f7e9a0aa25f3d0c1f0845eeb68e3dac4
The error comes from before 3.5.0 the following function _getSelectionBoundsFromContentEditable had a safe guard to only call getHostContenteditable if we have a valid rangeCount if (sel.rangeCount) {
//# get the first (usually only) range obj
const range = sel.getRangeAt(0)
const hostContenteditable = getHostContenteditable(range.commonAncestorContainer)
} After 3.5.0 const _getSelectionBoundsFromContentEditable = function (el) {
const doc = $document.getDocumentFromElement(el)
const hostContenteditable = getHostContenteditable(range.commonAncestorContainer)
const range = _getSelectionRange(doc)
const hostContenteditable = getHostContenteditable(range.commonAncestorContainer)
if (hostContenteditable === el) {
....
}
} I added back validation to check first if we have a valid range count : const _getSelectionBoundsFromContentEditable = function (el) {
const doc = $document.getDocumentFromElement(el)
const sel = doc.getSelection()
if (sel && sel.rangeCount) {
const range = _getSelectionRange(doc)
const hostContenteditable = getHostContenteditable(range.commonAncestorContainer)
if (hostContenteditable === el) {
return {
start: range.startOffset,
end: range.endOffset,
}
}
}
return {
start: 0,
end: 0,
}
} The test is green but I don't see any text get typed into the iframe @jennifer-shehane any insights into why this might be? Trying to wrap my head around this issue. |
I'm working on a fix for this |
@Naninani that issue you link is closed as fixed. Can you open a new one if you're still having that problem? |
The code for this is done in cypress-io/cypress#6571, but has yet to be released. |
Hello, since the code for this is done but it's not yet released, why is the ticket closed? Also, what version of cypress would we need to install to include the fix for this once this is fixed? |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
When trying to type inside of an iframe where the target element is either the body element with
contenteditable=true
or a child of the body, then an exception is throw from Cypress and the command fails. This worked successfully in 3.4.1, but is now failing in 3.7.0.We use the Froala wysiwyg editor library v2.9 which creates the editor as an iframe with the body element set with
contenteditable=true
. So we can no longer run e2e tests which type text into the editor with Cypress 3.7.0.Desired behavior:
Cypress successfully types into the specified element.
Steps to reproduce: (app code and test code)
An example of how to reproduce the error is by running the command,
With an iframe that contains,
This produces the following exception.
Versions
Cypress 3.7.0, 3.6.0, 3.5.0
The text was updated successfully, but these errors were encountered: