1

In my simple gmail chrome extension - I want to prevent loading of image in a sent mail.

Inside chrome.webRequest.onBeforeRequest.addListener is working when I include

urls: [ "*://*.googleusercontent.com/*" ]

in the urls array. But this will fire for all the images I only want to fire for this pattern "*://*/#https://mysite/*",

But it is not firing at all - If I include googleusercontent url it is working with details.url in this format - https://ci6.googleusercontent.com/proxy/IB4W2KvisZjL2rgC....#https://mysite/*

MANIFEST

"permissions": [
    "webRequest",
    "webRequestBlocking",
    "*://*.googleusercontent.com/*",
    "*://*/#https://track1/*",
    "*://*.googleusercontent.com/*/://track1/*"
],

and in the background script

chrome.webRequest.onBeforeRequest.addListener(
        function(details) {
            console.log(details);    
        }, {
        urls: [
            "*://*/#https://track1/*",
        ]
       }, ['blocking']
 );

I think issue is with patter matching but I am not able to understand which is the right pattern to use

Sandeep Chikhale
  • 1,505
  • 2
  • 21
  • 36

1 Answers1

1
chrome.webRequest.onBeforeRequest.addListener(
        function(details) {
           // Here inside details.url - you see each image is in format https://googlecontent 
            console.log(details);    
        }, {
        urls: [
            "*://*/#https://track1/*",
        ]
       }, ['blocking']
 );

As mentioned above Inside details.url - you see each image is in format https://googlecontent
So you need to include this pattern inside urls array.
Now how to grab required url link is

if (details.url.includes('<include link string here>') || details.url.includes('<other link here>')) {
    if (some condition to stop image load met) cancel = true;
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Sandeep Chikhale
  • 1,505
  • 2
  • 21
  • 36
  • Thanks, Sandeep! I also found the same solution. Your answer confirms that I was on the right track, :-) – Pallavi Goyal Sep 14 '18 at 18:21
  • 1
    We used this solution but looks like that with latest chrome 72, all *googleusercontent/proxy* urls are not being caught in the background script listener. Did you see it happening too? – Amiram Korach Feb 17 '19 at 16:44