[Webkit-unassigned] [Bug 278687] New: InvalidStateError is triggered for collapseToEnd() when switching the content to display:none

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Aug 26 18:20:11 PDT 2024


https://bugs.webkit.org/show_bug.cgi?id=278687

            Bug ID: 278687
           Summary: InvalidStateError is triggered  for collapseToEnd()
                    when switching the content to display:none
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: HTML Editing
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: karlcow at apple.com
                CC: wenson_hsieh at apple.com

Created attachment 472307

  --> https://bugs.webkit.org/attachment.cgi?id=472307&action=review

testcase

1. Load the attachment
2. Check the console.log for Safari, Firefox, Chrome

Safari is sending InvalidStateError while other browsers

Code from the testcase:

    <div id="test">
        <div contenteditable="true">
            <p>Some text</p>
        </div>
    </div>

    <p>Look at the console in Safari, Firefox and Chrome.</p>
    <p>Only Safari reports: <code>InvalidStateError: The object is in an invalid state.</code> for
        <code>collapseToEnd()</code></p>

    <script>
        function trigger_invalid_state(text_node) {
            text_node.parentNode.focus();
            var range = document.createRange();
            range.selectNode(text_node);
            range.setStart(text_node, 0);
            range.setEnd(text_node, 2);

            var sel = window.getSelection();
            sel.removeAllRanges();
            sel.addRange(range);
            window.getSelection().collapseToEnd();
        }


        var p_visible = document.querySelector('#test p');
        var text_node = p_visible.childNodes[0]
        console.log("visible: ", text_node);

        // no error
        trigger_invalid_state(text_node);

        // change it to display: none
        p_visible.parentNode.parentNode.style.display = "none";

        // call again
        trigger_invalid_state(text_node);

    </script>

I wonder if it's about focus on a display: none element

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20240827/cac67b09/attachment-0001.htm>


More information about the webkit-unassigned mailing list