# Firefox

### Configuration (about:config)
#### Useful about:config Settings
- `browser.tabs.splitView.enabled` - 像 Edge 分屏
- `xpinstall.signatures.required = false` - 允许本地安装未认证扩展文件
- `network.captive-portal-service.enabled = false` - 不尝试寻找 captive portals
- `network.notify.checkForProxies = false` - 不尝试寻找代理
- `browser.cache.disk.capacity = 8192000` - 增加磁盘缓存到 8GB
- `browser.cache.memory.capacity = 2097152` - 固定最大 2GB 内存缓存
- `browser.quitShortcut.disabled = true` - 防止意外关闭
- `browser.search.region = US`
- `doh-rollout.home-region = US`
- `gfx.webrender.all = true` - 启用 WebRender
- `layers.gpu-process.enabled = true` - GPU 进程加速
- `media.hardware-video-decoding.force-enabled = true`
- `media.ffmpeg.vaapi.enabled = true` - VAAPI 硬件解码
- `network.dnsCacheEntries = 20000` - DNS 缓存条目
- `network.dnsCacheExpiration = 3600` - DNS 缓存过期时间
- `network.ssl_tokens_cache_capacity = 32768` - TLS 令牌缓存
- `fission.autostart = false` - 禁用增强进程隔离（省内存）
- `dom.ipc.processCount = 1` - 减少进程数量
- `webgl.force-enabled = true`
- `toolkit.legacyUserProfileCustomizations.stylesheets = true` - 启用 userContent.css
- `dom.security.sanitizer.enabled = true` - 启用 setHTML 支持
- `reader.parse-on-load.enabled = false` - 关闭阅读器视图自动加载
- `media.peerconnection.enabled = false` - 禁用 WebRTC（隐私）
- `extensions.webextensions.restrictedDomains` - 限制扩展运行的域名

参考：
- https://github.com/arkenfox/user.js
- https://kb.mozillazine.org/About:config_entries
- https://wiki.archlinux.org/title/Firefox/
- https://wiki.archlinux.org/title/Firefox/Tweaks

#### Wayland Support
为 Firefox 添加环境变量：`MOZ_ENABLE_WAYLAND=1`。

`~/.config/environment.d/envvars.conf`：

```text
MOZ_ENABLE_WAYLAND=1
```

参考：
1. https://wiki.archlinux.org/title/Firefox#Wayland
2. https://wiki.archlinux.org/title/Environment_variables#Wayland_environment
3. https://bugzilla.mozilla.org/show_bug.cgi?id=wayland

#### DNS over HTTPS (DoH)
如果在 DoH 选择提供者的时候只有一个 custom，没有默认备选，可以尝试：
- 通过 UI 界面修改无线网的 DNS 为 `8.8.8.8,8.8.4.4`
- 设置 `network.trr.default_provider_uri = https://mozilla.cloudflare-dns.com/dns-query`
- 重启电脑后会出现 Cloudflare、NextDNS 等备选项

### Privacy & Security
#### Disable WebRTC
https://mullvad.net/en/help/webrtc

在 about:config 中设置 `media.peerconnection.enabled = false`。

#### Restrict Web Extensions on Domains
https://u.sb/firefox-no-webextensions/

打开 `about:config`，输入 `extensions.webextensions.restrictedDomains`，在后面加 `,example.com` 即可限制扩展在指定域运行。

默认限制域名：
```text
accounts-static.cdn.mozilla.net,accounts.firefox.com,addons.cdn.mozilla.net,addons.mozilla.org,api.accounts.firefox.com,content.cdn.mozilla.net,discovery.addons.mozilla.org,install.mozilla.org,oauth.accounts.firefox.com,profile.accounts.firefox.com,support.mozilla.org,sync.services.mozilla.com
```

### Extensions & Add-ons
#### Manifest v3
https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/

#### Build Extensions
如何打开一个新标签：https://github.com/tianheg/all-my-sites

Firefox 56 以后，扩展会自动获得自己 origin 的权限，不需要 tabs 权限。（https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions）

参考：
1. [Browser Extensions - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions)
2. [Getting started with web-ext | Firefox Extension Workshop](https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/)

#### Arch Linux Search Extension
https://aur.archlinux.org/packages/firefox-extension-arch-search

点击 Sources 的 *.xpi 文件即可安装。

#### TabMixPlus
https://github.com/onemen/TabMixPlus

### User Styles
#### Hide Tabbar (userChrome.css)
~/.mozilla/firefox/***.dev-edition-default/chrome/userChrome.css:

```css
#TabsToolbar {visibility: collapse;}
```

#### View Dark PDF
Bookmarklet 反转 PDF 颜色：

```javascript
javascript:(function(){var el = typeof viewer !== 'undefined' ? viewer : document.body; el.style.filter = 'grayscale(1) invert(1) sepia(1) contrast(75%)';})()
```

https://scottpaterson.ca/firefox-dark-mode-pdf/

### Troubleshooting
#### Network Errors
- `NS_ERROR_CORRUPTED_CONTENT` - 内容损坏错误

#### PR_END_OF_FILE_ERROR
使用 Proxy SwitchyOmega 扩展加 gfw list 导致 `PR_END_OF_FILE_ERROR` 错误。属于 VPN 配置问题。

参考：
- https://www.hostinger.com/tutorials/pr_end_of_file_error
- https://support.mozilla.org/en-US/questions/1315880

#### RSS File Open Loop
有的网站访问 RSS 页面时是下载 *.rss 文件。如果用 Firefox 打开，Firefox 可能不停地打开这个文件。删除本地文件即可停止。

#### Firefox Android
在 Firefox Android 上，JS bookmarklet 只能在空白页面运行。

### Performance
- https://xn--ime-zza.eu/3
- https://gist.github.com/RubenKelevra/fd66c2f856d703260ecdf0379c4f59db

### Browser Support
#### Element.setHTML Support
https://developer.mozilla.org/en-US/docs/Web/API/Element/setHTML

在 about:config 中设置 `dom.security.sanitizer.enabled = true`，重启 Firefox。


相关：[[js-expressjs|js-expressjs]]
