0

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 => {
                // ...
            }
        );
    }
);
wrager
  • 813
  • 1
  • 7
  • 25
  • 1
    I don't get the question. [`chrome.debugger.onDetach` is a thing](https://developer.chrome.com/extensions/debugger#event-onDetach). How is it not what you want? – Xan Nov 14 '18 at 11:20
  • Oh, I see, you're talking about debugger _feature_ within the devtools disabling. – Xan Nov 14 '18 at 11:21
  • @Xan No, I am talking about detaching debugger that was attached by chrome.debugger.attach, not the debugger feature. That is exactly what I looking for! Please post the answer and I will approve it. – wrager Nov 14 '18 at 11:41

2 Answers2

0

I made a workaround that suits me: setInterval with try/catch some debugger command.

const intervalId = setInterval(async () => {
    try {
        // await send 'Debugger.setBreakpointsActive' with active=true
    } catch (error) {
        clearInterval(intervalId);
        onDetach();
    }
}, 500);
wrager
  • 813
  • 1
  • 7
  • 25
0

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.

Xan
  • 74,770
  • 16
  • 179
  • 206