Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to fetch background colors on unstyled elements in Firefox #37

Closed
jdan opened this issue Jul 3, 2015 · 1 comment
Closed

Unable to fetch background colors on unstyled elements in Firefox #37

jdan opened this issue Jul 3, 2015 · 1 comment
Labels

Comments

@jdan
Copy link
Owner

jdan commented Jul 3, 2015

Related to #32. This may not be specific to FF.

Tracing through GoogleChrome/accessibility-developer-tools on FF, the following parseColor method:

/**
 * @param {string} colorString The color string from CSS.
 * @return {?axs.color.Color}
 */
axs.color.parseColor = function(colorString) {
    var rgbRegex = /^rgb\((\d+), (\d+), (\d+)\)$/;
    var match = colorString.match(rgbRegex);

    if (match) {
        var r = parseInt(match[1], 10);
        var g = parseInt(match[2], 10);
        var b = parseInt(match[3], 10);
        var a = 1;
        return new axs.color.Color(r, g, b, a);
    }

    var rgbaRegex = /^rgba\((\d+), (\d+), (\d+), (\d*(\.\d+)?)\)/;
    match = colorString.match(rgbaRegex);
    if (match) {
        var r = parseInt(match[1], 10);
        var g = parseInt(match[2], 10);
        var b = parseInt(match[3], 10);
        var a = parseFloat(match[4]);
        return new axs.color.Color(r, g, b, a);
    }

    return null;
};

When this method returns null, the getBgColor method that's used to compute the contrast ratio will also return null - which is causing the error.

This method expects to find rgb(...) and rgba(...) values for the CSSStyleDeclaration's backgroundColor property. In Firefox, unstyled elements have a backgroundColor of "transparent", while on Chrome the value is "rgba(0, 0, 0, 0)".

This might be worth reporting upstream, but in the meantime I can see if this is an isolated edge case and put up a quick patch.

@jdan
Copy link
Owner Author

jdan commented Jul 3, 2015

I've filed a bug upstream: GoogleChrome/accessibility-developer-tools#180

@jdan jdan closed this as completed in 9ccac40 Jul 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant