Skip to content

processStyleSheet function needs to use try/catch to avoid “SecurityError: The operation is insecure.” #20

@hellolindsay

Description

@hellolindsay

When elementQuery tries to load an external style sheet, some browsers will throw an error: “SecurityError: The operation is insecure.” -- this comment explains how to fix it.

The error is thrown from line 151 in the unminified source:
if (styleSheet[cssRules] && styleSheet[cssRules].length > 0) {

Using try/catch, we can detect this error and return instead of letting the script fail. The simplest way to do this is to add the following line right above the if-statement (add this line to line 151, pushing the if-statment to line 152)

try { styleSheet[cssRules].length; } catch(err) { return; }

With this in place, the security error and it’s side-effects will disappear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions