declarativeNetRequest does not work in Gmail

I'm not sure what is special about Gmail, but my declarativeNetRequest rules are totally ignored.

I make an web extension that blocks email trackers (1x1 pixel images embedded in emails to track if and when you open email sent to you). All images in Gmail are loaded through Google's proxy: googleusercontent.com/proxy/#originalURL

But no matter what I do, I can't block a single image that is loaded in an email. To try and prove it is a bug in Safari, I created a new template web extension in Xcode.

I block all resourceTypes (images and other should be all that is needed) and added two rules:

  1. Block all images loaded through Google's proxy server (this should block all embedded images in all emails)
  2. Block any image with copper in the URL (just in case the blocking doesn't apply to the proxy root url for some reason).
 {
  "id": 1,
  "priority": 1,
  "action": { "type": "block" },
  "isUrlFilterCaseSensitive": false,
  "condition": {
   "regexFilter": "googleusercontent.com/proxy",
   "resourceTypes": [
    "image",
    "media",
    "main_frame",
    "sub_frame",
    "stylesheet",
    "script",
    "font",
    "xmlhttprequest",
    "ping",
    "websocket",
    "other"
   ]
  }
 },
 {
  "id": 2,
  "priority": 1,
  "action": { "type": "block" },
  "isUrlFilterCaseSensitive": false,
  "condition": {
   "regexFilter": "copper",
   "resourceTypes": [
    "image",
    "media",
    "main_frame",
    "sub_frame",
    "stylesheet",
    "script",
    "font",
    "xmlhttprequest",
    "ping",
    "websocket",
    "other"
   ]
  }
 }
]

Even though I know this isn't needed, I also added the requester domain (mail.google.com) and the proxy domain (googleusercontent.com) to the permissions list in the manifest file:

  ...
  "declarative_net_request": {
    "rule_resources": [{
      "id": "ruleset_1",
      "enabled": true,
      "path": "rules.json"
     }]
  },

 "permissions": [
    "declarativeNetRequest",
    "*://mail.google.com/*",
    "*://*.googleusercontent.com/proxy/*"
  ]

If I open an email from copper, the image still loads in Gmail

If I right click and select "Open Image in New Tab", the image will not load and I am told it was blocked

If I open a test page that has two images in it, one the image from the email, the image is blocked and the other image is not (as expected, the second image is from wikipedia and should not be blocked)

Running the same extension in Chrome DOES block the image in Gmail (and in all the other cases too)

Can you please file a bug report on https://feedbackassistant.apple.com and include this sample extension? Let me know the feedback ID when you have.

Thanks!

I filed a bug report in July 2022 and it hasn't been responded to. The feedback ID is FB10544296

  • P.S. This post was locked when the wwdc21-10131 tag was applied which disabled my ability to reply, comment, or update the post.

Update after some more testing.

  • Good news: I CAN now block images in Gmail.
  • Bad news: I CAN NOT block images based on anything in the path after a "#" in Safari (where as I can in other browsers)

So if this is the url for the image I want to block:

https://ci3.googleusercontent.com/proxy/gHU4xG2VeSnDGYzSz5X#https://news.us13.list-manage.com/track/open.php?id=123

This rule WILL work:

 {
    "id": 1,
    "priority": 1,
    "action": { "type": "block" },
    "condition": {"regexFilter": "gHU4xG2VeSnDGYzSz5X", "resourceTypes": [ "image" ] }
},

This rule will NOT work:

 {
    "id": 1,
    "priority": 1,
    "action": { "type": "block" },
    "condition": {"regexFilter": "track", "resourceTypes": [ "image" ] }
},
declarativeNetRequest does not work in Gmail
 
 
Q