I'm not sure what is special about Gmail of if this is an issue on other sites as well, but my declarativeNetRequest rules are totally ignored in a Safari Extension that runs on Gmail.
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:
- Block all images loaded through Google's proxy server (this should block all embedded images in all emails)
- 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)
- = = = = = =
Sidenotes:
- This is a reposting of this post which was locked when the
wwdc21-10131
tag was applied to the post which disabled my ability to reply, comment, or update the post. Please do NOT apply tags that lock the post. - As requested on the original post by @bweinstein, I filed a bug report on Feedback assistant under FB 10544296 last year and haven't gotten any replies on it.
- I verified before reposting this (on Mar 1, 2023) that the bug still exists.