Magento 2 Debugging – JS UI Component in Browser

debuggingmagento2uicomponent

As i am searching debugging of ui component i don't find any great articles to debugging ui component in browser console so here i am writing my question.

As we all know magento current system is using knockout js, so i found this link
https://devdocs.magento.com/guides/v2.2/ui_comp_guide/troubleshoot/ui_comp_troubleshoot_js.html but i don't understand how it is work.

As per magento officials doc we can debug data as below link content.
https://devdocs.magento.com/guides/v2.2/ui_comp_guide/concepts/ui_comp_uiregistry.html

But as above link you have to know about your componentName for debugging it's data.

But my main concern is if i am currently accessing any custom module or core module form and I want to debug that form data from console then how ? because I don't know it's form namespace and it's tedious to find form namespace from element tab.

Best Answer

I made one solution after working on jquery function calling into console line by line.

As per debugging form data by uiRegistry https://devdocs.magento.com/guides/v2.2/ui_comp_guide/concepts/ui_comp_uiregistry.html.
We need componentName.

So for that I have created jQuery function.

Getting Grid Component

var gridComponentName = jQuery('div.admin__data-grid-outer-wrap:last').data('bind').split(': ',2)[1].replace(/'/g,'');

Getting Form Component

var formComponentname = jQuery('div.admin__form-loading-mask').data('component');

After getting main componentName you can pass it into registry

var registry = require('uiRegistry');
var component = registry.get(componentName);
console.log(component.namespace);

You can debug from this. Hope this will be helpful!.

Related Topic