46

I know there are tools like Wappalyzer & BuiltWith that give you information about which framework or library is used in a website. But I need some kind of proof regarding if ReactJs is really used in a website.

After some research I found out that commands like typeof React or window.React.version, but these commands don't work all the time.

Any ideas on how to check reactJs is used a web application?

2
  • 3
    try this one gist.github.com/rambabusaravanan/… Commented Jun 29, 2019 at 12:36
  • 1
    will post the answer, so later if someone checks they will be able to find it easily Commented Jun 29, 2019 at 12:40

5 Answers 5

61

try the below snippet, thanks for the examples for each site listed by rambabusaravanan. See the below link

if(!!window.React ||
   !!document.querySelector('[data-reactroot], [data-reactid]'))
  console.log('React.js');

if(!!window.angular ||
   !!document.querySelector('.ng-binding, [ng-app], [data-ng-app], [ng-controller], [data-ng-controller], [ng-repeat], [data-ng-repeat]') ||
   !!document.querySelector('script[src*="angular.js"], script[src*="angular.min.js"]'))
  console.log('Angular.js');

if(!!window.Backbone) console.log('Backbone.js');
if(!!window.Ember) console.log('Ember.js');
if(!!window.Vue) console.log('Vue.js');
if(!!window.Meteor) console.log('Meteor.js');
if(!!window.Zepto) console.log('Zepto.js');
if(!!window.jQuery) console.log('jQuery.js');

you can find additional info here link

Sign up to request clarification or add additional context in comments.

3 Comments

Your code doesn't work for Angular2+ frameworks (component based angular) you should add something like this: window.ng.coreTokens.NgZone, Also, please add support for Svelte. Other than that, nice solution
The React one doesn't work for a simple react app created by npx create-react-app my-app
I wrote an answer that should work even if React is encapsulated from the gobal scope via a bundler like webpack.
19

I had the same problem, and in my case, I found it better to rely on the React Developer Tools.

You can install it in Google Chrome, access the website you want to check, and open the Chrome DevTools.

If the website uses React, the React Developer Tools will include two tabs in the Chrome DevTools:

Chrome DevTools with React

Otherwise, the React Developer Tools won't include the tabs:

Chrome DevTools without React

1 Comment

For future readers, the addon is also available in Firefox. I wonder how does the addon developer detect whether to show the tab in the first place.
10

This answer doesn't detect the React 18 CRA apps that I've tried it on.

I can't edit that answer (stack overflow says too many pending edits) but it should also have a check for window.__REACT_DEVTOOLS_GLOBAL_HOOK__.

After adding that check it looks like this:

if(!!window.React || 
   !!window.__REACT_DEVTOOLS_GLOBAL_HOOK__ ||
   !!document.querySelector('[data-reactroot], [data-reactid]'))
  console.log('React.js');

if(!!document.querySelector('script[id=__NEXT_DATA__]'))
  console.log('Next.js');

if(!!document.querySelector('[id=___gatsby]'))
  console.log('Gatsby.js');

if(!!window.angular ||
   !!document.querySelector('.ng-binding, [ng-app], [data-ng-app], [ng-controller], [data-ng-controller], [ng-repeat], [data-ng-repeat]') ||
   !!document.querySelector('script[src*="angular.js"], script[src*="angular.min.js"]'))
  console.log('Angular.js');

if (!!window.getAllAngularRootElements ||
    !!window.ng?.coreTokens?.NgZone)
  console.log('Angular 2+');

if(!!window.Backbone) console.log('Backbone.js');
if(!!window.Ember) console.log('Ember.js');
if(!!window.Vue) console.log('Vue.js');
if(!!window.Meteor) console.log('Meteor.js');
if(!!window.Zepto) console.log('Zepto.js');
if(!!window.jQuery) console.log('jQuery.js');

1 Comment

@Learner maybe you can update your answer to include this new check?
4

There is an extension in Chrome named 'React Developer Tools' which allows you to inspect the React component hierarchies in the Chrome Developer Tools

https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi

There is also another extension named 'React-detector' as well :)

https://chrome.google.com/webstore/detail/react-detector/jaaklebbenondhkanegppccanebkdjlh

1 Comment

Thank you @cybercat. But I'm not looking for extensions or tools. I'm looking more for a command or code solution
4

Other answers that involve checking for globals like globalThis.React will work fine if the website uses react via a dedicated script HTML element, but will otherwise face the problem that bundlers like webpack can wrap dependency code inside immediately-invoked-function-expressions or other mechanisms for encapsulating their details and preventing them from unnecessarily bleeding into the global scope. Such encapsulation is very often desirable.

One can try to get around this by testing if DOM elements have properties on them that get set in React contexts, such as _reactRootContainer. Like so:

Array.from(document.querySelectorAll('*'))
  .some(e => e._reactRootContainer !== undefined)

A page can have tons of elements, so one can try to optimize based on an assumption that React code will call ReactDOM.createRoot and pass it an element queried via HTML id. Ie. instead of checking all DOM elements, only check those that have an id attribute. Like so:

Array.from(document.querySelectorAll('[id]'))
  .some(e => e._reactRootContainer !== undefined)

Be aware that the id-filtering optimization will not always work because the id assumption will not always hold.

Important: Since this method relies on the react DOM already having been created, it should be careful not to be applied until one thinks the react DOM has been created. Once can try to apply techniques like the defer attribute on scripts, or using document.onload, or setTimeout, or a combination of them.

Note that wrapping the nodelist from the query to turn it into an array is probably sub-optimal performance-wise, but I feel that to try to optimize it might be micro-optimizing. A check for the presence of react should probably be saved to a variable and never performed again anyway.

1 Comment

It returns false in all my React apps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.