Search code examples
google-chrome-extensiongoogle-chrome-devtoolschrome-debugging

Handle the debugger detaching in chrome extension


In accordance with the Debugger DevTools API, there is no debugger detach event. Can I catch the event for detaching the debugger when the user clicking "cancel" e.g.?

Sample code for attach:

chrome.debugger.attach(
    {
        tabId: tabId
    },
    '1.3',
    () => {
        chrome.debugger.sendCommand(
            {
                tabId: tabId
            },
            'Debugger.enable',
            {},
            result => {
                // ...
            }
        );
    }
);

Solution

  • If you're looking to catch your debugger connection being closed (as opposed to an event happening within that connection), there is a chrome.debugger.onDetach event provided by the API.