How to catch admin tab switching event

Tabs are used in many parts of Magento 2 administrative interface.
Here is I emplain how to catch admin tab switching event programmatically.

Magento 2 uses the standard jQuery UI Tabs Widget.
You need to catch the tabsactivate event.
I do it in this way:

var $tabs = $('#page_tabs');
if ($tabs.length) {
	/** @type HTMLDivElement */
	var tabContent = $textarea.closest('.ui-tabs-panel').get(0);
	if (tabContent) {
		$tabs.bind('tabsactivate', function(event, data) {
			if (data.newPanel.get(0) === tabContent) {
				// your code here
			}
		});
	}
}

$textarea.closest('.ui-tabs-panel').get(0) is a tab I need to handle.
data.newPanel.get(0) is a tab which is becoming active.