Skip to content

Instantly share code, notes, and snippets.

@easrng
Created November 10, 2024 20:18
Show Gist options
  • Save easrng/c4f6563524bee1b5eef6905dad7cf8f2 to your computer and use it in GitHub Desktop.
Save easrng/c4f6563524bee1b5eef6905dad7cf8f2 to your computer and use it in GitHub Desktop.
#!/bin/sh
_unix_connect_setup() {
if command -v busybox >/dev/null && busybox --list | grep ^nc$ >/dev/null && ! nc local: 2>&1 | grep 'bad port' >/dev/null; then
_unix_connect_cmd=busybox
_unix_connect_flags=nc
_unix_connect_prefix=local:
return
fi
if command -v nc >/dev/null && ! nc 2>&1 | grep BusyBox >/dev/null; then
_unix_connect_cmd=nc
_unix_connect_flags=-U
_unix_connect_prefix=
return
fi
if command -v ncat >/dev/null; then
_unix_connect_cmd=ncat
_unix_connect_flags=-U
_unix_connect_prefix=
return
fi
echo 'this script requires nc, ncat, or busybox nc with FEATURE_UNIX_LOCAL' >&2
exit 1
}
unix_connect() {
if [ -z "$_unix_connect_cmd"]; then
_unix_connect_setup
fi
"$_unix_connect_cmd" $_unix_connect_flags "$_unix_connect_prefix$1"
}
PROFILE="$(mktemp -d)"
SOCK="$PROFILE/fxui.sock"
trap 'kill $FX_PID; rm -rf "$PROFILE"; trap - EXIT INT HUP TERM; exit' EXIT INT HUP TERM
cat <<"_EOF" >"$PROFILE/user.js"
user_pref("app.normandy.api_url", "");
user_pref("app.update.checkInstallTime", false);
user_pref("app.update.disabledForTesting", true);
user_pref("apz.content_response_timeout", 60000);
user_pref("browser.contentblocking.features.standard", "-tp,tpPrivate,cookieBehavior0,-cm,-fp");
user_pref("browser.dom.window.dump.enabled", true);
user_pref("browser.newtabpage.activity-stream.feeds.system.topstories", false);
user_pref("browser.newtabpage.enabled", false);
user_pref("browser.pagethumbnails.capturing_disabled", true);
user_pref("browser.safebrowsing.blockedURIs.enabled", false);
user_pref("browser.safebrowsing.downloads.enabled", false);
user_pref("browser.safebrowsing.malware.enabled", false);
user_pref("browser.safebrowsing.phishing.enabled", false);
user_pref("browser.search.update", false);
user_pref("browser.sessionstore.resume_from_crash", false);
user_pref("browser.shell.checkDefaultBrowser", false);
user_pref("browser.startup.homepage", "about:blank");
user_pref("browser.startup.homepage_override.mstone", "ignore");
user_pref("browser.startup.page", 0);
user_pref("browser.tabs.disableBackgroundZombification", false);
user_pref("browser.tabs.warnOnCloseOtherTabs", false);
user_pref("browser.tabs.warnOnOpen", false);
user_pref("browser.translations.automaticallyPopup", false);
user_pref("browser.uitour.enabled", false);
user_pref("browser.urlbar.suggest.searches", false);
user_pref("browser.usedOnWindows10.introURL", "");
user_pref("browser.warnOnQuit", false);
user_pref("datareporting.healthreport.documentServerURI", "http://dummy.test/dummy/healthreport/");
user_pref("datareporting.healthreport.logging.consoleEnabled", false);
user_pref("datareporting.healthreport.service.enabled", false);
user_pref("datareporting.healthreport.service.firstRun", false);
user_pref("datareporting.healthreport.uploadEnabled", false);
user_pref("datareporting.policy.dataSubmissionEnabled", false);
user_pref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
user_pref("devtools.jsonview.enabled", false);
user_pref("dom.disable_open_during_load", false);
user_pref("dom.file.createInChild", true);
user_pref("dom.ipc.reportProcessHangs", false);
user_pref("dom.max_chrome_script_run_time", 0);
user_pref("dom.max_script_run_time", 0);
user_pref("extensions.autoDisableScopes", 0);
user_pref("extensions.enabledScopes", 5);
user_pref("extensions.getAddons.cache.enabled", false);
user_pref("extensions.installDistroAddons", false);
user_pref("extensions.screenshots.disabled", true);
user_pref("extensions.update.enabled", false);
user_pref("extensions.update.notifyUser", false);
user_pref("extensions.webservice.discoverURL", "http://dummy.test/dummy/discoveryURL");
user_pref("focusmanager.testmode", true);
user_pref("general.useragent.updates.enabled", false);
user_pref("geo.provider.testing", true);
user_pref("geo.wifi.scan", false);
user_pref("hangmonitor.timeout", 0);
user_pref("javascript.options.showInConsole", true);
user_pref("media.gmp-manager.updateEnabled", false);
user_pref("media.sanity-test.disabled", true);
user_pref("network.cookie.sameSite.laxByDefault", false);
user_pref("network.http.prompt-temp-redirect", false);
user_pref("network.http.speculative-parallel-limit", 0);
user_pref("network.manage-offline-status", false);
user_pref("network.sntp.pools", "dummy.test");
user_pref("plugin.state.flash", 0);
user_pref("privacy.trackingprotection.enabled", false);
user_pref("remote.enabled", true);
user_pref("security.certerrors.mitm.priming.enabled", false);
user_pref("security.fileuri.strict_origin_policy", false);
user_pref("security.notification_enable_delay", 0);
user_pref("services.settings.server", "http://dummy.test/dummy/blocklist/");
user_pref("signon.autofillForms", false);
user_pref("signon.rememberSignons", false);
user_pref("startup.homepage_welcome_url", "about:blank");
user_pref("startup.homepage_welcome_url.additional", "");
user_pref("toolkit.cosmeticAnimations.enabled", false);
user_pref("toolkit.startup.max_resumed_crashes", -1);
user_pref("devtools.chrome.enabled", true);
user_pref("devtools.debugger.remote-enabled", true);
user_pref("devtools.debugger.prompt-connection", false);
user_pref("remote.active-protocols", 1);
user_pref("fission.webContentIsolationStrategy", 0);
_EOF
MOZ_REMOTE_SETTINGS_DEVTOOLS=1 firefox --profile "$PROFILE" --start-debugger-server "$SOCK" --chrome chrome://extensions/content/dummy.xhtml &
FX_PID=$!
FIFO="$PROFILE/fxui.fifo"
mkfifo "$FIFO"
exec 3<>"$FIFO"
until [ -e "$SOCK" ]; do sleep 0.2; done
BUF=
send() {
printf '%s:%s' "${#1}" "$1" >&3
}
send '{"type":"getProcess","id":0,"to":"root"}'
unix_connect "$SOCK" <&3 | while true; do
read -rN 1 BYTE || exit
if [ "$BYTE" = ":" ]; then
read -rN $BUF MESSAGE
PROCESS_ACTOR="$(printf '%s\n' "$MESSAGE" | grep -Po '(?<="processDescriptor":{"actor":")([^"]+)')"
if [ ! -z "$PROCESS_ACTOR" ]; then
echo "actor: $PROCESS_ACTOR" >&2
send '{"type":"getTarget","to":"'"$PROCESS_ACTOR"'"}'
fi
CONSOLE_ACTOR="$(printf '%s\n' "$MESSAGE" | grep -Po '(?<="consoleActor":")([^"]+)')"
if [ ! -z "$CONSOLE_ACTOR" ]; then
echo "consoleActor: $CONSOLE_ACTOR" >&2
send '{"type":"evaluateJSAsync","text":"Services.prefs.setBoolPref(\"devtools.debugger.prompt-connection\", true)\nfetch(\"file://\"+\"'"$(realpath "$1")"'\".split(\"/\").map(encodeURIComponent).join(\"/\")).then(r=>r.text()).then(c=>new Function(c)())","disableBreaks":false,"to":"'"$CONSOLE_ACTOR"'"}'
fi
echo $MESSAGE >&2
BUF=
else
BUF="$BUF$BYTE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment