/
githubmirror
/
browser-extension
Обзор
Документация
Войти
/
githubmirror
/
browser-extension
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/helpers/chromeDebugger.ts
38 строк
1 KB
David Corbitt
Big bang
08 апр 2023, 04:27
08 апр 2023, 04:27
56260be
Код
Авторство
О чём код?
export function attachDebugger(tabId: number) { return new Promise<void>((resolve, reject) => { try { chrome.debugger.attach({ tabId }, '1.2', async () => { if (chrome.runtime.lastError) { console.error( 'Failed to attach debugger:', chrome.runtime.lastError.message ); reject( new Error( `Failed to attach debugger: ${chrome.runtime.lastError.message}` ) ); } else { console.log('attached to debugger'); await chrome.debugger.sendCommand({ tabId }, 'DOM.enable'); console.log('DOM enabled'); await chrome.debugger.sendCommand({ tabId }, 'Runtime.enable'); console.log('Runtime enabled'); resolve(); } }); } catch (e) { reject(e); } }); } export async function detachDebugger(tabId: number) { const targets = await chrome.debugger.getTargets(); const isAttached = targets.some( (target) => target.tabId === tabId && target.attached ); if (isAttached) { chrome.debugger.detach({ tabId: tabId }); } }