Am trying to get all the sub-resources or urls or fetch/xhr (i hope am communicating well) from a webpage.
I've tried using the chrome.webRequest API but it did'nt get me all the sub-resources/fetch/xhr called on the page unlike when i tried using chrome.debugger which gets me exactly what I want, allow me to showcase the code.
Here is the same question on, Stack Overflow
SOLUTION 1
chrome.webRequest.onBeforeRequest.addListener( (details) => { console.log("all resource URL:", details.url, details.initiator, "\n"); }, { urls: ["<all_urls>"] } )
SOLUTION 2
chrome.action.onClicked.addListener((tab) => { console.log("action button has been clicked\n") chrome.debugger.attach({ tabId: tab.id }, '1.0', () => { chrome.debugger.sendCommand({ tabId: tab.id }, 'Network.enable', {}, () => { chrome.debugger.onEvent.addListener((source, method, params) => { if (source.tabId === tab.id && method === 'Network.responseReceived') { if (params.response.mimeType === 'application/json' && params.response.url.includes("url")) { console.log(params.response, "\n") console.log(params.response.url)
And yes, unlike the webRequest version I have narrowed my search in the chrome.debugger to json responses, which is actually what I want but the debugging warning would not be nice for the users. So here are my troubles;
2a) I prefer the chrome.webRequest approach, very clean, but how do i make it give me all fetch/xhr like i see on my network tab?
2b) I did notice it fetched me a url. Which is actually a js script, which is the initiator for the url i want, how to i get down into the script to get that particular url. I saw it in the "Request Iniator chain" of the js script.