I have experienced the same issue in a jQuery plugin that I'm modifying for my own use. Basically, you can see from documentation that the parameter passed into getComputedStyle
must be of type Element
. Your plugin is passing window
, the global variable pointing to the browser window, which is of type Window
(who would have guessed?) into the function call. Their code looks something like this, I'm guessing:
var x = window.getComputedStyle(e);
They're probably calling this from a generic function that didn't verify that e
is actually an Element
and not a Window
.
In my case, I'm only trying to circumvent the jQuery width()
method on elements and include the border width and padding width. (It was a true doozy to figure out why I had to do that.) I reviewed how jQuery determines if the element is a Window
and handled it similarly. Ultimately, this is what I ended up doing in my use case:
function getWidth(e) {
if (e != null && e === e.window) {
return $(e).width();
}
const css = window.getComputedStyle(e[0]);
const width = parseInt(css.width);
const pLeft = parseInt(css.paddingLeft);
const pRight = parseInt(css.paddingRight);
const bLeft = parseInt(css.borderLeft);
const bRight = parseInt(css.borderRight);
return width + pLeft + pRight + bLeft + bRight;
}