johnmichel / Library-Detector-for-Chrome

🔍 Extension that detects which JavaScript libraries are running on a page
https://chrome.google.com/webstore/detail/cgaocdmhkmfnkdkbnckgmpopcbpaaejo
MIT License
662 stars 111 forks source link

Removes CRA detection #172

Closed housseindjirdeh closed 4 years ago

housseindjirdeh commented 4 years ago

Since there's no easy way to detect Create React App on a page, this implementation requested for an asset-manifest.json file that would break auth flows in some sites (e.g. Bitbucket)

Until we find a viable solution, it's probably safest to remove entirely 😞

johnmichel commented 4 years ago

Looks great! Hopefully, we can re-add this in the future. In my mind, this'll bump things to a new major version.

Thanks for taking care of it, @housseindjirdeh.

developit commented 4 years ago

Apologies for resurrecting this PR, but one potential way to detect CRA is by combining a check for their near-universally-kept <noscript> and a React root. The noscript tag has been included with the same text since 2017.

    'Create React App': {
        id: 'create-react-app',
        icon: 'cra',
        url: 'https://create-react-app.dev/',
        npm: 'react-scripts',
        test: async function (win) {
            let child = win.document.body.firstElementChild;
            let noscript, root;
            do {
                if (child.localName === 'noscript') noscript = child;
                else if (child.id === 'root') root = child;
            } while (child = child.nextElementSibling);
            if (root && noscript && /You need to enable JavaScript to run this app/.test(noscript.textContent)) {
                return { version: UNKNOWN_VERSION };
            }
        }
    },
housseindjirdeh commented 4 years ago

Thanks @developit! I've been staying away from only using their specific noscript tag but if we couple that with a React root I think that could be pretty fool-proof to a degree :)

@johnmichel What do you think? If you're okay with it, I'll put up a PR and bump to a new major version!

developit commented 4 years ago

Only if you think it's close enough. I figured checking the exact text of the noscript will make this likely to be biased towards false negatives, which is probably okay.

johnmichel commented 4 years ago

Looks great! Thanks, @developit and @housseindjirdeh