【问题标题】:How to Block Image Loading in GMAILS Chrome Extension?如何在 GMAILS Chrome 扩展程序中阻止图像加载?
【发布时间】:2018-11-23 10:39:33
【问题描述】:

在我简单的 gmail chrome 扩展程序中 - 我想防止在已发送邮件中加载图像。

当我包含时,chrome.webRequest.onBeforeRequest.addListener 内部正在工作

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

在 urls 数组中。但这会触发我只想为此模式触发的所有图像"*://*/#https://mysite/*",

但它根本没有触发 - 如果我包含 googleusercontent url,它正在以这种格式使用 details.url - https://ci6.googleusercontent.com/proxy/IB4W2KvisZjL2rgC....#https://mysite/*

清单

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

后台脚本

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

我认为问题在于模式匹配,但我无法理解哪种模式适合使用

【问题讨论】:

  • 嗨桑迪普!你得到所需的图案了吗?或任何其他解决方案?
  • 是的@PallaviGoyal 我终于找到了问题。让我解释下面的答案

标签: google-chrome google-chrome-extension gmail inboxsdk


【解决方案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']
 );

如上所述,在 details.url 内部 - 您会看到每个图像的格式为 https://googlecontent
所以你需要在 urls 数组中包含这个模式。
现在如何获取所需的 url 链接是

if (details.url.includes('<include link string here>') || details.url.includes('<other link here>')) {
    if (some condition to stop image load met) cancel = true;
}

【讨论】:

  • 谢谢,桑迪普!我也找到了相同的解决方案。您的回答证实我走在正确的轨道上,:-)
  • 我们使用了这个解决方案,但看起来与最新的 chrome 72 类似,所有 googleusercontent/proxy url 都没有被后台脚本侦听器捕获。你也看到了吗?
猜你喜欢
  • 2014-06-04
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-06
  • 2019-10-25
  • 1970-01-01
相关资源
最近更新 更多