Yes there is a way to prevent this. You need to add code that will block such requests. This kind of request can be made with two different urls:
1. If you are composing a message, gmail will call your url directly for your browser.
2. If you are viewing the message you sent, gmail will use its proxy. It won't call it directly from your browser and the url will be different, like *
googleusercontent.com*[some long hash].
The way to do it is to add a background script that will block the calls, or better, redirect them to a noop endpoint so there won't be any errors in network log.
For direct urls we're redirecting them from "mail-opened" to "mail-opened-noop" and in the server we just return the pixel and ignore it.
For proxy urls, you don't want to block all such urls, just the tracking ones. The problem is that this url doesn't have your url in it, but if you include a query string, gmail will add your url at the end.
browser.webRequest.onBeforeRequest.addListener(details => {
// we got here because we redirected to it
if (details.url.includes('mail-opened-noop')) {
return; // continue to make the request. The server will ignore it.
}
// block pixel images requested through gmail proxy. they cannot be redirected. They will include 'mail-opened' if there was a query string in your url
if (details.url.includes('googleusercontent.com/proxy') && details.url.includes('mail-opened')) {
return {
cancel: true
};
}
const redirectUrl = details.url.replace('mail-opened', 'mail-opened-noop');
console.log(`Redirecting mail opened request from ${details.url} to ${redirectUrl}`);
return {
redirectUrl
};
}, {urls: ['*://*/mail-opened/*', '*://*.googleusercontent.com/proxy/*']}, ['blocking']);