Skip to content
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

window.getSelection().toString() returns [object Selection] not the selected text #319

Closed
felixscheinost opened this issue Feb 25, 2021 · 7 comments
Assignees

Comments

@felixscheinost
Copy link

According to MDN window.getSelection().toString() is supposed to return the text the user selected.

I am using this by checking that the selection is empty that the user is actually clicking and not selecting text.

The problem is that when running in HtmlUnit this method is always returning [object Selection] and not the selected text.

@rbri
Copy link
Member

rbri commented Feb 25, 2021

will have a look - thanks for the report

@rbri
Copy link
Member

rbri commented Feb 25, 2021

it will be a great help if you can provide some test cases for different selections

see com.gargoylesoftware.htmlunit.javascript.host.dom.SelectionTest

@rbri rbri self-assigned this Feb 25, 2021
@rbri
Copy link
Member

rbri commented Apr 16, 2021

Yes this is clearly a bug, but i fear it will be not that simple to provide a correct selection implementation.
But i will try to make a first shot on this.

Can you please tell me a bit more about your use case - what do you like to do with the selected text, what kind of selections you are doing?

@rbri rbri added this to In Implementation in HtmlUnit - RBRi Apr 16, 2021
@rbri rbri closed this as completed in ed55e61 Apr 16, 2021
@rbri
Copy link
Member

rbri commented Apr 16, 2021

The implicit conversion was already working, now toString() produces the same result.

@rbri
Copy link
Member

rbri commented Apr 16, 2021

As always will inform on twitter if a new snapshot is available.

Many thanks for the report.

@felixscheinost
Copy link
Author

Sorry, for coming back to you just now.

I used it for checking whether the user had selected some text in an onClick listener to filter out clicks while the user is selecting text. As a workaround I used window.getSelection().type === "Range" instead to check whether text is selected.

Thanks a lot for your help!

@rbri
Copy link
Member

rbri commented Apr 23, 2021

Thanks for the feedback, the current snapshot impl. has a fix for the toString() method that should do the job for your case.

BTW: i found two more classes with the same error - thanks again for using HtmlUnit and the error report.

@rbri rbri removed this from In Implementation in HtmlUnit - RBRi Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants