首页 > 解决方案 > 如何在 GeckoFX Windows Forms 网络浏览器中获取广告拦截?

问题描述

我正在使用 GeckoFX45 在 Windows 窗体中运行浏览器。我希望能够添加一个广告拦截器(uBlock 或 AdBlock Plus)。

大多数广告拦截器都是针对 IE 的,并且 GeckoPreferences.Default("extensions.blocklist.enabled") = False;给了我一个错误。

有没有办法在 GeckoFX 浏览器中实现 Adblock?

标签: c#geckofxadblock

解决方案


尝试将 Firefox 扩展添加到 GeckoFX

首先,添加使用部署扩展的位置

Xpcom.ComponentRegistrar.AutoRegister():

void RegisterExtensionDir(string dir)
{
        Console.WriteLine("Registering binary extension directory:  " + dir);
        var chromeDir = (nsIFile)Xpcom.NewNativeLocalFile(dir);
        var chromeFile = chromeDir.Clone();
        chromeFile.Append(new nsAString("chrome.manifest"));
        Xpcom.ComponentRegistrar.AutoRegister(chromeFile);
}

其次,不要在扩展的 chrome.manifest 中使用 ABI 标志。所以而不是

binary-component components/GeckoScraper.dll  ABI=WINNT_x86-msvc

利用

binary-component components/GeckoScraper.dll

推荐阅读