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

MutationObserver.observe check for options argument is too strict #1223

Closed
romansp opened this issue Jan 18, 2024 · 0 comments · Fixed by #1224
Closed

MutationObserver.observe check for options argument is too strict #1223

romansp opened this issue Jan 18, 2024 · 0 comments · Fixed by #1224
Labels
bug Something isn't working

Comments

@romansp
Copy link
Contributor

romansp commented Jan 18, 2024

Describe the bug
MutationObserver.observe check for options argument is too strict and throws DOMException for the cases when it's valid according to the DOM Standard.

It should also throw TypeError and not DOMException in case when options object is invalid.

To Reproduce
Steps to reproduce the behavior:

  1. Run the following code in 'happy-dom' environment
let div = document.createElement('div');
let text = document.createTextNode('old');
let observer = new MutationObserver(() => console.log('mutated'));
observer.observe(div, { attributeFilter: ['style', 'class'] });
observer.observe(text, { characterDataOldValue: true });

Expected behavior
Should not throw DOMException or TypeError.

Device:

  • Version 13.1.4

Additional context
According to the DOM Standard the following steps should be performed first before checking options.

  1. If either options["attributeOldValue"] or options["attributeFilter"] exists, and options["attributes"] does not exist, then set options["attributes"] to true.
  2. If options["characterDataOldValue"] exists and options["characterData"] does not exist, then set options["characterData"] to true.

Discovered while running tests against codebase with VueUse usage. Here MutationObserver is used with just attributeFilter: https://github.com/vueuse/vueuse/blob/84965f53edc73b221804de91e565ffdf71d1e28d/packages/core/useElementBounding/index.ts#L96-L98

@romansp romansp added the bug Something isn't working label Jan 18, 2024
romansp added a commit to romansp/happy-dom that referenced this issue Jan 18, 2024
@romansp romansp changed the title MutationObserver.observer check for options argument is too strict MutationObserver.observe check for options argument is too strict Jan 18, 2024
romansp added a commit to romansp/happy-dom that referenced this issue Jan 18, 2024
…options` argument. Throw `TypeError` instead of `DOMException` when validation fails.
romansp added a commit to romansp/happy-dom that referenced this issue Jan 18, 2024
…options` argument. Throw `TypeError` instead of `DOMException` when validation fails.
capricorn86 added a commit that referenced this issue Feb 26, 2024
…erve-options-validation

#1223@patch: Relax `MutationObserver.observe` check for `options` argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant