elementQuery icon indicating copy to clipboard operation
elementQuery copied to clipboard

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

Open hellolindsay opened this issue 11 years ago • 0 comments

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.

hellolindsay avatar Aug 18 '14 16:08 hellolindsay