profile.set_preference('capability.policy.maonoscript.sites','

def _firefox_profile():
    """Configure the Firefox profile, respecting FIREFOX_PROFILE_PATH if set"""
    profile_dir = os.environ.get(FIREFOX_PROFILE_ENV_VAR)

    if profile_dir:
        LOGGER.info("Using firefox profile: %s", profile_dir)
        try:
            firefox_profile = webdriver.FirefoxProfile(profile_dir)
        except OSError as err:
            if err.errno == errno.ENOENT:
                raise BrowserConfigError(
                    "Firefox profile directory {env_var}={profile_dir} does not exist".format(
                        env_var=FIREFOX_PROFILE_ENV_VAR, profile_dir=profile_dir))
            elif err.errno == errno.EACCES:
                raise BrowserConfigError(
                    "Firefox profile directory {env_var}={profile_dir} has incorrect permissions. It must be \
                    readable and executable.".format(env_var=FIREFOX_PROFILE_ENV_VAR, profile_dir=profile_dir))
            else:
                # Some other OSError:
                raise BrowserConfigError(
                    "Problem with firefox profile directory {env_var}={profile_dir}: {msg}"
                    .format(env_var=FIREFOX_PROFILE_ENV_VAR, profile_dir=profile_dir, msg=str(err)))
    else:
        LOGGER.info("Using default firefox profile")
        firefox_profile = webdriver.FirefoxProfile()

        # Bypasses the security prompt displayed by the browser when it attempts to
        # access a media device (e.g., a webcam)
        firefox_profile.set_preference('media.navigator.permission.disabled', True)

        # Disable the initial url fetch to 'learn more' from mozilla (so you don't have to
        # be online to run bok-choy on firefox)
        firefox_profile.set_preference('browser.startup.homepage', 'about:blank')
        firefox_profile.set_preference('startup.homepage_welcome_url', 'about:blank')
        firefox_profile.set_preference('startup.homepage_welcome_url.additional', 'about:blank')
    for function in FIREFOX_PROFILE_CUSTOMIZERS:
        function(firefox_profile)
    return firefox_profile

5
1

                                    def fetch_adblockplus_list(output_directory, wait_time=20):
    """ Saves an updated AdBlock Plus list to the specified directory.
    <output_directory> - The directory to save lists to. Will be created if it
                         does not already exist.
    """
    output_directory = os.path.expanduser(output_directory)
    # Start a virtual display
    display = Display(visible=0)
    display.start()

    root_dir = os.path.dirname(__file__)
    fb = FirefoxBinary(os.path.join(root_dir,'../firefox-bin/firefox'))

    fp = webdriver.FirefoxProfile()
    browser_path = fp.path + '/'

    # Enable AdBlock Plus - Uses "Easy List" by default
    # "Allow some non-intrusive advertising" disabled
    fp.add_extension(extension=os.path.join(root_dir,'DeployBrowsers/firefox_extensions/adblock_plus-2.7.xpi'))
    fp.set_preference('extensions.adblockplus.subscriptions_exceptionsurl', '')
    fp.set_preference('extensions.adblockplus.subscriptions_listurl', '')
    fp.set_preference('extensions.adblockplus.subscriptions_fallbackurl', '')
    fp.set_preference('extensions.adblockplus.subscriptions_antiadblockurl', '')
    fp.set_preference('extensions.adblockplus.suppress_first_run_page', True)
    fp.set_preference('extensions.adblockplus.notificationurl', '')

    # Force pre-loading so we don't allow some ads through
    fp.set_preference('extensions.adblockplus.please_kill_startup_performance', True)

    print "Starting webdriver with AdBlockPlus activated"
    driver = webdriver.Firefox(firefox_profile = fp, firefox_binary = fb)
    print "Sleeping %i seconds to give the list time to download" % wait_time
    time.sleep(wait_time)

    if not os.path.isdir(output_directory):
        print "Output directory %s does not exist, creating." % output_directory
        os.makedirs(output_directory)

    print "Copying blocklists to %s" % output_directory
    try:
        shutil.copy(browser_path+'adblockplus/patterns.ini', output_directory)
        shutil.copy(browser_path+'adblockplus/elemhide.css', output_directory)
    finally:
        driver.close()
        display.stop()

5 (1 Votes)
0
4.17
6

                                    def init_browser(br_type, cmd_args=""):
    
    if br_type is 'firefox':
        fp = webdriver.FirefoxProfile()        
        #fp.add_extension(extension=os.path.expanduser('~pathto/fourthparty.xpi')) # TODO: integrate fourthparty 
        return webdriver.Firefox(firefox_profile=fp)    
    else:
        ch = webdriver.ChromeOptions()
        ch.binary_location = CHROME_MOD_BINARY
        for cmd_arg in cmd_args:
            if cmd_arg:
                ch.add_argument(cmd_arg)
                #wl_log.info("Chrome arguments %s" % cmd_arg)
            
        return webdriver.Chrome(executable_path=CHROME_DRIVER_BINARY,
                                  chrome_options=ch)

4.17 (6 Votes)
0
3.7
10
Bdkopen 125 points

                                        @fc.timing
    def setup_profile(self, firebug=True, netexport=True):
        """
        Setup the profile for firefox
        :param firebug: whether add firebug extension
        :param netexport: whether add netexport extension
        :return: a firefox profile object
        """
        profile = webdriver.FirefoxProfile()
        profile.set_preference("app.update.enabled", False)
        if firebug:
            profile.add_extension(os.path.join(self.cur_path, 'extensions/firebug-2.0.8.xpi'))
            profile.set_preference("extensions.firebug.currentVersion", "2.0.8")
            profile.set_preference("extensions.firebug.allPagesActivation", "on")
            profile.set_preference("extensions.firebug.defaultPanelName", "net")
            profile.set_preference("extensions.firebug.net.enableSites", True)
            profile.set_preference("extensions.firebug.delayLoad", False)
            profile.set_preference("extensions.firebug.onByDefault", True)
            profile.set_preference("extensions.firebug.showFirstRunPage", False)
            profile.set_preference("extensions.firebug.net.defaultPersist", True)  # persist all redirection responses
        if netexport:
            har_path = os.path.join(self.cur_path, "har")
            if not os.path.exists(har_path):
                os.mkdir(har_path)
            profile.add_extension(os.path.join(self.cur_path, 'extensions/netExport-0.9b7.xpi'))
            profile.set_preference("extensions.firebug.DBG_NETEXPORT", True)
            profile.set_preference("extensions.firebug.netexport.alwaysEnableAutoExport", True)
            profile.set_preference("extensions.firebug.netexport.defaultLogDir", har_path)
            profile.set_preference("extensions.firebug.netexport.includeResponseBodies", True)
        return profile

3.7 (10 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source