NEW278687
InvalidStateError is triggered for collapseToEnd() when switching the content to display:none
https://bugs.webkit.org/show_bug.cgi?id=278687
Summary InvalidStateError is triggered for collapseToEnd() when switching the conten...
Karl Dubost
Reported 2024-08-26 18:20:11 PDT
Created attachment 472307 [details] 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
Attachments
testcase (1.39 KB, text/html)
2024-08-26 18:20 PDT, Karl Dubost
no flags
Radar WebKit Bug Importer
Comment 1 2024-08-26 18:20:51 PDT
John A. Bilicki III
Comment 2 2024-08-27 09:09:32 PDT
Hi Karl, I would technically argue that I would rather become aware of the issue than not. Though at the same time a good question would be: is this error message necessary in this instance? I can't commit to getting too involved right now though I just wanted to throw these thoughts in real quick since you had the courtesy to mention this in my bug report 278290, thank you.
Karl Dubost
Comment 3 2024-08-27 15:47:08 PDT
Hi John, This bug is about understanding the difference of behavior in between Safari on one side and Firefox/Chrome on the other side. And help us determine which browsers act in accordance with the specifications and/or what makes sense.
Ahmad Saleem
Comment 4 2024-09-02 14:00:02 PDT
Here - https://searchfox.org/wubkat/rev/b36cbce69fddb7da33823f316bd8ead5bebee970/Source/WebCore/page/DOMSelection.cpp#249 We can update our error message, if we want. return Exception { ExceptionCode::InvalidStateError }; to return Exception { ExceptionCode::InvalidStateError, "something something"_s }; __ Meanwhile I found something in Blink (closely touching or mentioning potential issue or could be totally different issue) - https://issues.chromium.org/issues/40277798
Karl Dubost
Comment 5 2024-09-02 20:26:56 PDT
Ahmad, the bug to fix the error message is Bug 278290. Not this one. :)
Note You need to log in before you can comment on or make changes to this bug.