Skip to content

Don't use window constructors in instance checks #98

@Joozty

Description

@Joozty

Constructors are not shared between window instances. So for example if you have an HTML element in an iframe this check will fail:

iframeDiv instanceof window.Element

Read more here

I suggest using a different strategy to check if the given parameter is an Element. For example, using tagName

MWE:

import { ResizeObserver } from "resize-observer";

document.getElementById("app").innerHTML = `
<iframe></iframe>
`;

const resizeObserver = new ResizeObserver((entries) => {
  for (let entry of entries) {
    console.log(entry);
  }
});

const iframe = document.querySelector("iframe");

resizeObserver.observe(iframe.contentDocument.body);

iframe.contentDocument.body.style.width = "300px";

Codesanbox here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions