Skip to content

Commit

Permalink
Expose the HtmlUnit web client as underlying in HtmlUnitBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
ruippeixotog committed Jun 4, 2017
1 parent ccbab81 commit c4f383e
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import net.ruippeixotog.scalascraper.util._
class HtmlUnitBrowser(browserType: BrowserVersion = BrowserVersion.CHROME) extends Browser {
type DocumentType = HtmlUnitDocument

private[this] lazy val client = {
lazy val underlying: WebClient = {
val c = ProxyUtils.getProxy match {
case Some((proxyHost, proxyPort)) => new WebClient(browserType, proxyHost, proxyPort)
case None => new WebClient(browserType)
Expand All @@ -49,7 +49,7 @@ class HtmlUnitBrowser(browserType: BrowserVersion = BrowserVersion.CHROME) exten

def exec(req: WebRequest): HtmlUnitDocument = {
val window = newWindow()
client.getPage(window, req)
underlying.getPage(window, req)
HtmlUnitDocument(window)
}

Expand Down Expand Up @@ -87,14 +87,14 @@ class HtmlUnitBrowser(browserType: BrowserVersion = BrowserVersion.CHROME) exten
}

def cookies(url: String) =
client.getCookies(new URL(url)).asScala.map { c => c.getName -> c.getValue }.toMap
underlying.getCookies(new URL(url)).asScala.map { c => c.getName -> c.getValue }.toMap

def clearCookies() = client.getCookieManager.clearCookies()
def clearCookies() = underlying.getCookieManager.clearCookies()

/**
* Closes all windows opened in this browser.
*/
def closeAll() = client.close()
def closeAll() = underlying.close()

protected[this] def defaultClientSettings(client: WebClient): Unit = {
client.getOptions.setCssEnabled(false)
Expand All @@ -119,8 +119,8 @@ class HtmlUnitBrowser(browserType: BrowserVersion = BrowserVersion.CHROME) exten
req
}

private[this] def newWindow(): WebWindow = client.synchronized {
client.openTargetWindow(client.getCurrentWindow, null, UUID.randomUUID().toString)
private[this] def newWindow(): WebWindow = underlying.synchronized {
underlying.openTargetWindow(underlying.getCurrentWindow, null, UUID.randomUUID().toString)
}
}

Expand Down

0 comments on commit c4f383e

Please sign in to comment.