Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert to headless puppeteer #5

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

cameronaaron
Copy link
Contributor

Summary:
This pull request replaces Electron with Puppeteer for headless browser automation in the Matrix-Google Voice bridge. The key motivation for this change is to reduce resource usage and simplify deployment, especially in containerized environments.

Key Changes:
Browser Initialization:

Replaced Electron-based initialization with Puppeteer.
Puppeteer now handles launching a headless browser to interact with Google Voice.

Script Injection:

Script loading previously done via webContents in Electron is now handled with page.addScriptTag() in Puppeteer.

Request Interception:

Network request interception logic has been moved to Puppeteer’s page.on('request', ...) to block unnecessary requests and allow only essential ones.

JavaScript Execution:

Replaced Electron’s webContents.executeJavaScript() with Puppeteer’s page.evaluate() to execute custom scripts within the browser context.

Inter-Process Communication (IPC):

Retained the same IPC mechanism (stdin and stdout) for communication between the Go application and the headless browser, ensuring backward compatibility.
File Renaming:

Benefits:
Reduced Overhead: Puppeteer is lighter than Electron, leading to lower resource usage.
Easier Containerization: Puppeteer integrates better with containers, eliminating the need for Electron’s GUI components.
More Streamlined Dependencies: Fewer dependencies are required compared to Electron.
Testing:
Successfully tested all major functionalities, including:
Browser initialization
Script injection
Request interception
JavaScript execution
IPC communication

@chaoticbear
Copy link

chaoticbear commented Jan 23, 2025

@cameronaaron Should this PR work? I am trying to run it with a customized dockerfile chaoticbear#2, that should run puppeteer and puppeteer installed globally, but getting an error: Error: Cannot find module 'puppeteer'

@mooomooo
Copy link

I have it installed and running, thanks for this branch!

However, I'm seeing the same issue as #4 -- I can receive messages just fine, and if I send messages from the web interface it shows up in my matrix chat windows, but anytime I try to send from matrix, I get error 429. Any thoughts?

@cameronaaron
Copy link
Contributor Author

oh I forgot I started this i'm surprised it even works that much :/ I will look at this tomorrow and finish it up

@mooomooo
Copy link

mooomooo commented Feb 3, 2025

For what it's worth, I see that I've made two slight changes, presumably because it didn't work otherwise? I don't exactly remember what happened, or whether it's specific to this branch vs main, but this is the current state of my repo:

  • RUN go build -o /usr/bin/mautrix-gvoice
    • RUN sh build.sh -o /usr/bin/mautrix-gvoice
  • go build -ldflags="-s -w $GO_LDFLAGS" ./cmd/mautrix-gvoice "$@"
    • go build -ldflags="-s -w $GO_LDFLAGS" "$@" ./cmd/mautrix-gvoice

I've never used go, so I don't know if this is actually necessary to get the docker to build, or if this is just me somehow being silly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants