wavesurfer.js icon indicating copy to clipboard operation
wavesurfer.js copied to clipboard

instanceof checks in iframes

Open anilanar opened this issue 3 months ago • 2 comments

Bug description

There are some rare use cases where elements are rendered into a different iframe. For example: https://github.com/ryanseddon/react-frame-component . Considering it has 1.8k stars, I guess it's common enough of a use case.

When done so, expressions such as element instanceof HTMLElement would evaluate to always false because an iframe's HTMLElement is not the same as window/globalThis.HTMLElement. In such cases, one usually needs to either:

  • Take a custom optional window as option and do el instanceof customWindow.HTMLElement
  • Or if that's not needed (if there are workarounds for all global variable/class/etc. usages), write code accordingly such as el instanceof el.ownerDocument.defaultView.HTMLElement.
  • Or avoid such strict checks and assume it's an element.

Currently wavesurfer doesn't work in such cases because, for example, parentFromOptionsContainer uses instanceof HTMLElement which always returns false. One would hope there'd be a workaround, but there sadly isn't because the other fallback document.querySelector would fail too because document !== iframe.document, so it would search in the wrong document.

anilanar avatar Sep 24 '25 02:09 anilanar

Thanks for the heads up. Do we need this issue though? I don't see it as something actionable for us.

katspaugh avatar Sep 24 '25 07:09 katspaugh

I (or somebody else) could eventually make a PR to either make those checks less dependent on globalThis, or if that isn't possible for all cases, I could introduce an option such as window, as done by some component libraries or css-in-js libraries.

anilanar avatar Sep 24 '25 11:09 anilanar