Files
chrome-extensions-samples/api-samples/debugger/background.js
IanStanion-google 2f74f5563f Debugger (#950)
* Implement debugger API mv3 sample

* Expands the debugger sample to make use of captured network data

* Update manifest.json

* Create README.md

* Update README.md
2023-06-21 20:55:20 +02:00

26 lines
744 B
JavaScript

chrome.action.onClicked.addListener(function (tab) {
if (tab.url.startsWith('http')) {
chrome.debugger.attach({ tabId: tab.id }, '1.2', function () {
chrome.debugger.sendCommand(
{ tabId: tab.id },
'Network.enable',
{},
function () {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
}
}
);
});
} else {
console.log('Debugger can only be attached to HTTP/HTTPS pages.');
}
});
chrome.debugger.onEvent.addListener(function (source, method, params) {
if (method === 'Network.responseReceived') {
console.log('Response received:', params.response);
// Perform your desired action with the response data
}
});