1

I am working on chrome extension where I have a requirement to intercept and block certain XHR requestes that are originating inside iframe. I tried below code, but its intercepting only top frame requests

chrome.webRequest.onBeforeRequest.addListener(
    () => { 
      console.log('Request will be blocked here, if request is interceped');
      return {cancel: true}
    }, 
    { urls: ['*://*/*'], types: ['main_frame','sub_frame']}, 
    ['blocking']
);
Vaibhav
  • 2,073
  • 4
  • 23
  • 26
  • What is the URL of the iframe and the request it makes? P.S. Did you reload the extension after editing? – wOxxOm Oct 06 '21 at 14:58
  • @wOxxOm Here is Iframe url - https://ppc-excel.officeapps.live.com/x/_layouts/xlviewerinternal.aspx and one xhr request that originiates from this iframe has this url https://ppc-excel.officeapps.live.com/x/_layouts/MruV2ServiceHandler.ashx – Vaibhav Oct 07 '21 at 16:47
  • After removing types: ['main_frame','sub_frame'] from above code it started intercepting requests inside iframe also. An way thanks @wOxxOm – Vaibhav Oct 08 '21 at 03:49
  • 1
    Ah, indeed `sub_frame` means the request that creates the iframe itself, not its own requests. – wOxxOm Oct 08 '21 at 05:55

0 Answers0