Include instance
and window
on HookOptions
#301
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When experimenting with hooks, I found the context provided in
HookOptions
to be insufficient for some use cases. For example, I wanted to prevent a script from callingalert()
by replacing the call with the construction of adialog
using anapply
hook:I found this wasn't possible because the proxied DOM is not exposed to the hook (which I'm here accessing via
opts.window.document
). So this PR exposes thewindow
as a property onHookOptions
.Another use was trying to solve for was to restrict DOM mutations to the subtree of a given element. I found this was not possible because the
instance
is not exposed onHookOptions
. When it is, I can walk up the DOM node ancestor in a hook to determine if the hook should be prevented or not:(As the
@todo
notes, this is not going to catch all cases. For example, when mutating an inlinestyle
there is noparentNode
property available for theCSSStyleDeclaration
instance being modified.)