Firefox in WebAssembly: Porting a Browser to WASM

Firefox in WebAssembly: Porting a Browser to WASM

Firefox in WebAssembly Overview

Firefox in WebAssembly 是一個技術演示,將 Firefox 瀏覽器引擎移植到 WebAssembly (WASM),讓完整的瀏覽器可以在另一個網頁瀏覽器中執行。該專案實作了透過基於 WebGL 的渲染來進行網頁內容的 GPU 加速,並包含一個實驗性的 JavaScript-to-WASM 即時編譯器 (JIT) 以提升執行速度。

Technical Architecture and Implementation

Rendering and Execution

  • GPU Acceleration: 該專案利用 WebGL 來處理網頁內容的渲染,在 WASM 環境中提供硬體加速。
  • Experimental JIT: 為了提升效能,該專案包含一個 JS $\rightarrow$ WASM JIT 編譯器。開發者指出,此功能為實驗性功能,可能包含錯誤。
  • Networking: 網頁內容並非直接由 WASM 實例載入;相反地,它是透過 WebSockets 經由 Puter 託管的 Wisp 伺服器進行代理。這種架構意味著網路流量是從代理伺服器發出,而非使用者的本地機器。

Compatibility and Requirements

  • JSPI Support: 該專案需要 WebAssembly JavaScript Promise Integration (JSPI) 才能運作。若使用者使用的瀏覽器不支援 JSPI,將無法載入此演示。
  • Recursive Execution: 作者確認,技術上可以在 "firefox-wasm inside firefox-wasm inside firefox" 中執行,儘管系統在此層級的遞迴執行時會變得非常不穩定。

Community Insights and Technical Challenges

Performance and Development Cost

開發此移植版本時,在 AI 輔助編碼方面投入了大量資源。作者提到,移植成本超過了 "25k in opus/fable tokens for debugging and JIT research," 強調了 LLM 在複雜移植任務中的角色。

Security and Privacy Concerns

社群成員對基於代理的網路模型提出了疑慮。由於流量是透過 Puter 託管的伺服器進行路由,使用者的 IP 地址會被遮蔽,且伺服器擁有者可以看見流量。

All the network traffic from that browser is routed through a server. My IP inside that browser was in India and on CloudFlare network. I don’t particularly trust Puter.

Practical Use Cases and Limitations

使用者已指出此移植版本的幾個潛在應用與限制:

  • Bypassing Restrictions: 一些使用者建議使用此方法在受限的 OS 環境(例如 VIDAA OS)中執行廣告攔截器(如 uBlock Origin),在這些環境中原生瀏覽器禁止使用擴充功能。
  • Mobile Support: 該專案目前缺乏穩健的行動裝置支援。回報的問題包括 IME/鍵盤無法運作、複製貼上功能失效,以及在 Android Chrome 上的觸控捲動失敗。
  • Stability: 一些使用者在特定瀏覽器版本(例如 aarch64 上的 Firefox 152.0.6)嘗試執行此演示時,回報了 SecurityErrorunsupported syscall: __syscall_madvise 錯誤。

Comparison to Prior Art

技術討論指向了 WebKit.js,作為將 WebKit 渲染引擎移植到 JavaScript 的先前範例,這暗示了將完整的渲染引擎嵌入到網頁平台中的趨勢。

Sources