0

In my extension I'm trying to attach debugger for given tabId, Here is my code

if(!attachedTabIds.includes(tabId)) {
    chrome.debugger.attach({ tabId: tabId }, version, function(){
        ...
    })
}

So from time to time I'm getting this error

enter image description here

I tried to wrap it with try/catch block but it didn't work.

try {
    chrome.debugger.attach({ tabId: tabId }, version, function(){
        ...
    })
} catch(e){
    console.log('e', e)
}

SO how can I handle this error ?

0

1 Answer 1

1

You handle the error by checking the value of chrome.runtime.lastError in the callback function that you passed to chrome.debugger.attach()

if (!attachedTabIds.includes(tabId)) {
    chrome.debugger.attach(
        {tabId: tabId},
        version,
        function() {
            if (chrome.runtime.lastError) {
                console.log("Error");
                console.log(chrome.runtime.lastError);
            }
            else {
                console.log("Success");
            }
        }
    );
}

https://developer.chrome.com/docs/extensions/reference/runtime/#property-lastError

lastError

This will be defined during an API method callback if there was an error

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.