<commit_before>package crawler.service;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.HashSet;
import java.util.Set;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.gargoylesoftware.htmlunit.BrowserVersion;

import crawler.EmailCrawlerConfig;

public class DriveBrowserService {

	protected static WebDriver dr;
	protected int screen_height;

	DriveBrowserService(boolean hasGUI) {
		if (hasGUI) {
			System.setProperty("webdriver.chrome.driver", EmailCrawlerConfig.getConfig().readString("chrome-driver-path"));
			this.dr = new ChromeDriver();
		} else {
			// this.dr = new HtmlUnitDriver(BrowserVersion.CHROME, true);
			DesiredCapabilities caps = new DesiredCapabilities();
			caps.setJavascriptEnabled(true);
			caps.setCapability("takesScreenshot", false);
			caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
					EmailCrawlerConfig.getConfig().readString("phantom-driver-path"));
			String[] args = new String[] {"--webdriver-loglevel=NONE"};
			caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args);
			this.dr = new PhantomJSDriver(caps);
			Dimension size = this.dr.manage().window().getSize();
			screen_height = size.height;
		}
	}

	/**
	 * use extension in the Chrome browser<commit_msg>correct screen_size bug in scroll<commit_after>package crawler.service;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.HashSet;
import java.util.Set;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.gargoylesoftware.htmlunit.BrowserVersion;

import crawler.EmailCrawlerConfig;

public class DriveBrowserService {

	protected static WebDriver dr;
	protected int screen_height;

	DriveBrowserService(boolean hasGUI) {
		if (hasGUI) {
			System.setProperty("webdriver.chrome.driver", EmailCrawlerConfig.getConfig().readString("chrome-driver-path"));
			this.dr = new ChromeDriver();
		} else {
			// this.dr = new HtmlUnitDriver(BrowserVersion.CHROME, true);
			DesiredCapabilities caps = new DesiredCapabilities();
			caps.setJavascriptEnabled(true);
			caps.setCapability("takesScreenshot", false);
			caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
					EmailCrawlerConfig.getConfig().readString("phantom-driver-path"));
			String[] args = new String[] {"--webdriver-loglevel=NONE"};
			caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args);
			this.dr = new PhantomJSDriver(caps);
		}
		screen_height = this.dr.manage().window().getSize().height;
	}

	/**
	 * use extension in the Chrome browser
{'fraction_non_alphanumeric': 0.11101670914755027, 'fraction_numerical': 0.0, 'mean_word_length': 5.939096267190569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4153480', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1130, 'n_words': 184}