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 is not a function #457

Closed
cll123456 opened this issue Apr 21, 2022 · 4 comments · Fixed by #459
Closed

window.getSelection is not a function #457

cll123456 opened this issue Apr 21, 2022 · 4 comments · Fixed by #459
Assignees
Labels
enhancement New feature or request

Comments

@cll123456
Copy link

I use vitest to test my component, but my component use window.getSelection() api, i get errors as follows:

image

@Mas0nShi
Copy link
Contributor

Mas0nShi commented Apr 21, 2022

you can use polyfill window.getSelection = document.getSelection.
but Selection is not really implemented.
e.g.

document.getSelection() == document.getSelection()
// in happy-dom: false
// in chromium : true

only this now.
packages/happy-dom/src/selection/Selection.ts

You can call Document.getSelection(), which works identically to Window.getSelection()

Refer:
https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection
https://w3c.github.io/selection-api/#dom-window-getselection

@cll123456
Copy link
Author

you can use polyfill window.getSelection = document.getSelection. but Selection is not really implemented. e.g.

document.getSelection() == document.getSelection()
// in happy-dom: false
// in chromium : true

only this now. packages/happy-dom/src/selection/Selection.ts

You can call Document.getSelection(), which works identically to Window.getSelection()

Refer: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection https://w3c.github.io/selection-api/#dom-window-getselection

@Mas0nShi Thank you very much for your reply😀

document.getSelection() is ok, but when i use document.createRange() , i get new error:

image

@capricorn86 capricorn86 added the enhancement New feature or request label Apr 26, 2022
@capricorn86 capricorn86 self-assigned this Apr 26, 2022
@capricorn86 capricorn86 linked a pull request Apr 26, 2022 that will close this issue
capricorn86 added a commit that referenced this issue Apr 26, 2022
…is-not-a-function

#457@minor: Adds support for Window.getSelection().
@capricorn86
Copy link
Owner

Thank you for helping out @Mas0nShi! 🙂

@capricorn86
Copy link
Owner

@thanks for reporting @cll123456! 🙂

I have now added support for Window.getSelection().

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants