Skip to content

Commit

Permalink
Merge branch 'master' into stealth_extension
Browse files Browse the repository at this point in the history
  • Loading branch information
vringar committed Feb 7, 2024
2 parents d343064 + f72e7ca commit 0cfc12f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 12 additions & 4 deletions openwpm/deploy_browsers/deploy_firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ def deploy_firefox(

# Intercept logging at the Selenium level and redirect it to the
# main logger.
interceptor = FirefoxLogInterceptor(browser_params.browser_id)
interceptor.start()
webdriver_interceptor = FirefoxLogInterceptor(
browser_params.browser_id, is_webdriver=True
)
webdriver_interceptor.start()

browser_interceptor = FirefoxLogInterceptor(
browser_params.browser_id, is_webdriver=False
)
browser_interceptor.start()

# Set custom prefs. These are set after all of the default prefs to allow
# our defaults to be overwritten.
Expand All @@ -141,15 +148,16 @@ def deploy_firefox(
status_queue.put(("STATUS", "Launch Attempted", None))

fo.binary = FirefoxBinary(
firefox_path=firefox_binary_path, log_file=open(interceptor.fifo, "w")
firefox_path=firefox_binary_path, log_file=open(browser_interceptor.fifo, "w")
)
geckodriver_path = subprocess.check_output(
"which geckodriver", encoding="utf-8", shell=True
).strip()
driver = webdriver.Firefox(
options=fo,
service=Service(
executable_path=geckodriver_path, log_output=open(interceptor.fifo, "w")
executable_path=geckodriver_path,
log_output=open(webdriver_interceptor.fifo, "w"),
),
)

Expand Down
11 changes: 8 additions & 3 deletions openwpm/deploy_browsers/selenium_firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ class FirefoxLogInterceptor(threading.Thread):
instance.
"""

def __init__(self, browser_id: BrowserId) -> None:
threading.Thread.__init__(self, name="log-interceptor-%i" % browser_id)
def __init__(self, browser_id: BrowserId, is_webdriver: bool) -> None:
threading.Thread.__init__(
self,
name=f"log-interceptor-{'webdriver' if is_webdriver else 'browser'}-{browser_id}",
)
self.browser_id = browser_id
self.fifo = mktempfifo(suffix=".log", prefix="owpm_driver_")
self.daemon = True
self.logger = logging.getLogger("openwpm")
assert self.fifo is not None

def run(self) -> None:
# We might not ever get EOF on the FIFO, so instead we delete
Expand All @@ -70,7 +74,8 @@ def run(self) -> None:
if self.fifo is not None:
os.unlink(self.fifo)
self.fifo = None

except Exception:
self.logger.error("Error in LogInterceptor", exc_info=True)
finally:
if self.fifo is not None:
os.unlink(self.fifo)
Expand Down

0 comments on commit 0cfc12f

Please sign in to comment.