Skip to content

Commit

Permalink
firefox 使用两种方式启动多实例
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjingxyk committed Oct 10, 2023
1 parent 8469151 commit cae6c36
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 21 deletions.
91 changes: 91 additions & 0 deletions tools/firefox-web-ext.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

set -exu

__DIR__=$(
cd "$(dirname "$0")"
pwd
)
cd ${__DIR__}

__PROJECT__=$(
cd ${__DIR__}/../
pwd
)

OS=$(uname -s)
ARCH=$(uname -m)
echo "$OS"

FIREFOX=''
UUID=''
case $OS in
"Linux")
UUID=$(cat /proc/sys/kernel/random/uuid)
FIREFOX=${__PROJECT__}/var/firefox/firefox
;;
"Darwin")
UUID=$(uuidgen)
# macos firefox 默认启动目录
FIREFOX='/Applications/Firefox.app/Contents/MacOS/firefox'
# 自定义 启动目录
FIREFOX="${__PROJECT__}/var/Firefox/Firefox.app/Contents/MacOS/firefox-bin"
;;
'MINGW64_NT'* | 'MSYS_NT'*)
;;
*)
echo 'current script no support !'
;;
esac


profile_folder="/tmp/${UUID}"

mkdir -p $profile_folder


mkdir -p ${__PROJECT__}/var/
cd ${__PROJECT__}/var/


# python3 ${__PROJECT__}/extension/tools/update-manifest.py firefox

# firefox web extension
# https://github.com/mdn/webextensions-examples.git

# https://wiki.mozilla.org/Firefox/CommandLineOptions

# firefox use Manifest V3
# https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/

# declarativeNetRequestWithHostAccess 声明式网络请求
# https://github.com/mdn/webextensions-examples/blob/main/dnr-dynamic-with-options/manifest.json
# "permissions": ["declarativeNetRequestWithHostAccess"],
# "optional_host_permissions": ["*://*/"],
# "optional_permissions": ["*://*/"],

# 支持 ResourceType
# https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest/ResourceType


# 它使用 user.js 中的相应设置覆盖 prefs.js 中的任何设置。
cp -f ${__PROJECT__}/tools/prefs.js $profile_folder

# 进入扩展所在目录
cd ${__PROJECT__}/extension-v2/

# reference https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#web-ext-run

npx web-ext run \
--verbose \
--firefox=${FIREFOX} \
--firefox-profile=$profile_folder \
--profile-create-if-missing \
--arg="--new-tab=https://stackoverflow.com/tags/socat/hot?filter=all" \
--start-url https://m3.material.io/

# --devtools \
# --browser-console \


exit 0
25 changes: 4 additions & 21 deletions tools/firefox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,7 @@ cd ${__PROJECT__}/var/
# 它使用 user.js 中的相应设置覆盖 prefs.js 中的任何设置。
cp -f ${__PROJECT__}/tools/prefs.js $profile_folder

# 进入扩展所在目录
cd ${__PROJECT__}/extension-v2/

# reference https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#web-ext-run

npx web-ext run \
--verbose \
--firefox=${FIREFOX} \
--firefox-profile=$profile_folder \
--profile-create-if-missing \
--arg="--new-tab=https://stackoverflow.com/tags/socat/hot?filter=all" \
--start-url https://m3.material.io/

# --devtools \
# --browser-console \


exit 0

# export MOZ_ENABLE_WAYLAND=1
# 启动firefox 实例

${FIREFOX} \
-profile "$profile_folder" \
Expand All @@ -105,9 +86,11 @@ ${FIREFOX} \
# -jsconsole \
# about:blank

# 此命令已不可用 ; Firefox 允许通过 RDP(远程调试协议)安装插件
# 此命令已不可用
# -install-global-extension ${__ROOT__}/extension-v2 \
# -install-global-extension ${__DIR__}/traduzir_paginas_web-9.8.1.0.xpi \

# 新版Firefox 允许通过 RDP(远程调试协议)安装插件
# gecko-dev
# https://github.com/mozilla/gecko-dev.git

0 comments on commit cae6c36

Please sign in to comment.