#!/usr/bin/env bash
# Start geckodriver in the background, writing its filtered log to $1
# (default: selenium.log).
set -e

selenium_log="${1:-selenium.log}"

# Drive geckodriver directly over W3C; no Java Selenium server is needed.
# Drop all benign Firefox-internal JavaScript errors: they originate from
# "resource://" modules (FormHandler, Sqlite, BackupService, PrivateBrowsingUtils,
# ...). Real app errors come from https:// URLs and are kept.
# "The operation was aborted" comes from XHRs cancelled by navigating away.
gecko_log_noise='resource://|The operation was aborted'
sudo geckodriver --port 4444 --log error 2>&1 | grep --line-buffered -vE "$gecko_log_noise" | sudo tee "$selenium_log" >/dev/null &
