使用geckodriver进行的Firefox v67私人浏览并不总是启用插件

时间:2019-06-17 17:02:49

标签: python firefox-addon geckodriver selenium-firefoxdriver

最新的Firefox 67版本已禁用私人浏览加载项。可以按照本指南进行添加。 https://support.mozilla.org/en-US/kb/extensions-private-browsing

问题在于,即使使用该指南,插件也无法在geckodriver下始终启用。

这在Firefox v66中没有问题。

  1. 我已经运行了一个实例,该实例具有默认的firefox配置文件(profile.ini中的Profile0)和两个附加组件(线圈和LastPass)。我看到插件弹出约2秒钟,然后消失。
  2. 我已通过以下方法在私有浏览器中手动启用了它们:插件。看来,如果已经在浏览器中启用了它们以供私人浏览器使用,并且在私人浏览中不可见,则将权限更改为禁止以仍然在私人浏览中启用它们,然后允许它们使它们保持启用状态。很奇怪。
  3. 我卸载了一个插件,关闭了所有浏览器,再次启动了脚本,并且该脚本首次运行。然后在第二次运行时,又回到了启用的2秒,然后如上所述消失了。
  4. 我检查了当geckodriver复制配置文件以供使用时在temp下创建的临时配置文件。包含附件。
  5. 手动打开专用浏览器会显示两个加载项,因此它似乎特定于geckodriver + firefox v67。但是,专用浏览器没有让我登录我的插件。

        def get_firefox_profile_dir(self):
        from pathlib import Path
        self.gecko_path = os.path.dirname(__file__)

        if sys.platform in ['linux', 'linux2']:
            import subprocess
            self.ff_gecko = Path(self.gecko_path + '/geckodriver')

            bits = 'uname -m'
            ver_32_64 = subprocess.getstatusoutput(bits)

            cmd = "ls -d /home/$USER/.mozilla/firefox/*.default/"
            fp = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE)
            FF_PRF_DIR = fp.communicate()[0][0:-2]
            FF_PRF_DIR_DEFAULT = str(FF_PRF_DIR, 'utf-8')

            ff_ext_path = os.path.join(FF_PRF_DIR_DEFAULT, 'extensions')
            self.ff_coil_loc = os.path.join(ff_ext_path, self.ff_coil_extId)
            ff_coil_enabled = os.path.exists(self.ff_coil_loc)
            if ff_coil_enabled:
                if 'x86_64' in ver_32_64:
                    if not self.ff_gecko.is_file():
                        import wget
                        self.gecko_targz = 'geckodriver-v0.24.0-linux64.tar.gz'
                        wget.download(self.gecko_source_linux64, self.gecko_path)
                        self.file_unzip_tar(self.gecko_path + '/' + self.gecko_targz)
                        os.remove(self.gecko_path  + '/' + self.gecko_targz)
                    if self.ff_gecko.is_file():
                            self.data_path = FF_PRF_DIR_DEFAULT
                            self.gecko = self.ff_gecko
                            return
                if 'i368' in ver_32_64:
                    if not self.ff_gecko.is_file():
                        import wget
                        self.gecko_targz = 'geckodriver-v0.24.0-linux32.tar.gz'
                        wget.download(self.gecko_source_linux32, self.gecko_path)
                        self.file_unzip_tar(self.gecko_path + '/' + self.gecko_targz)
                        os.remove(self.gecko_path + '/' + self.gecko_targz)
                    if self.ff_gecko.is_file():
                            self.data_path = FF_PRF_DIR_DEFAULT
                            self.gecko = self.ff_gecko
                            return
        elif sys.platform == 'win32' or 'nt':
            from pathlib import Path
            self.gecko = self.gecko_path + "\geckodriver.exe"
            mozilla_profile = os.path.join(os.getenv('APPDATA'), r'Mozilla\Firefox')
            mozilla_profile_ini = os.path.join(mozilla_profile, r'profiles.ini')
            profile = configparser.ConfigParser()
            profile.read(mozilla_profile_ini)

            FF_PRF_DIR_DEFAULT = os.path.normpath(os.path.join(mozilla_profile, profile.get('Profile0', 'Path')))
            ff_ext_path = os.path.join(FF_PRF_DIR_DEFAULT, 'extensions')
            self.ff_coil_loc = os.path.join(ff_ext_path, self.ff_coil_extId)
            ff_coil_enabled = os.path.exists(self.ff_coil_loc)

            if ff_coil_enabled:
                ff_gecko = Path(self.gecko)
                if ff_gecko.is_file():

                    self.data_path = FF_PRF_DIR_DEFAULT
                    return
                else:
                    import wget
                    wget.download(self.gecko_source_win64)
                    self.file_zunip('geckodriver-v0.24.0-win64.zip')
                    if ff_gecko.is_file():
                        os.remove('geckodriver-v0.24.0-win64.zip')
                        self.data_path = FF_PRF_DIR_DEFAULT

                        return
self.get_firefox_profile_dir()
            self.driver = webdriver.Firefox(options=self.options, firefox_profile=self.data_path, executable_path=self.gecko)
            self.driver.get(self.url)  # OPEN URL

我希望FF插件已启用,因为已从浏览器中手动允许它们,并且它们将以正常模式登录。

1 个答案:

答案 0 :(得分:0)

似乎核心问题与升级到v67有关,并且配置文件中的一些未知项目已损坏。配置文件重置解决了该问题。

https://support.mozilla.org/en-US/kb/refresh-firefox-reset-add-ons-and-settings

更新:经过进一步的测试,我发现它显示了短期稳定性,并且动态加载时扩展会被命中和遗漏(更多遗漏)。换句话说,配置文件重置插件在最初工作了几次之后便不再加载硒

相关问题