Skip to content

getStyles of an element inside the shadow dom #2341

@edoardocavazza

Description

@edoardocavazza

Hi,

Using Polymer in my application, I have found out that the function

var getStyles = function( elem ) {
    // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
    // IE throws on elements created in popups
    // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
    if ( elem.ownerDocument.defaultView.opener ) {
        return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
    }

    return window.getComputedStyle( elem, null );
};

throws an exception when elem is a shadow dom element, because elem.ownerDocument.defaultView is undefined.

Adding the control, all works well.

if ( elem.ownerDocument.defaultView && elem.ownerDocument.defaultView.opener ) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions