From 570eedf904a0d5b8d71f09663ba4ce5651b70b2e Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Thu, 8 Jul 2021 02:08:20 -0400 Subject: [PATCH] Auto-derive the installed LINE extension's UUID --- SETUP.md | 6 +---- puppet/README.md | 3 --- puppet/example-config.json | 1 - puppet/prep_helper.js | 46 -------------------------------------- puppet/src/main.js | 1 - puppet/src/puppet.js | 13 +++++++++-- 6 files changed, 12 insertions(+), 58 deletions(-) delete mode 100644 puppet/prep_helper.js diff --git a/SETUP.md b/SETUP.md index 4886840..12868e8 100644 --- a/SETUP.md +++ b/SETUP.md @@ -21,11 +21,7 @@ 1. If your system's CPU architecture is not x86\_64, the version of Chromium bundled with Puppeteer will not work, and the following steps are required: 1. Install Chrome/Chromium from your distribution's package manager 1. Set `executable_path` in `puppet/config.json` to the path to the installed Chrome/Chromium binary -1. Run `node prep_helper.js` to open Chrome/Chromium with the downloaded LINE extension enabled, and click on the LINE icon next to the URL bar -1. Once the LINE popup appears, press F12 to show DevTools, which will reveal the LINE extension's UUID -1. Edit `puppet/config.json` with some important settings: - * set `"url"` to the UUID found in the previous step - * set the `"listen"` settings to the socket to use for communication with the bridge (see [puppet/README.md](puppet/README.md) for details) +1. Edit `puppet/config.json` with desired settings (see [puppet/README.md](puppet/README.md) for details) ## Bridge 1. `cd` to the project root directory and create a Python virtual environment with `python3 -m venv .venv`, and enter it with `source .venv/bin/activate` diff --git a/puppet/README.md b/puppet/README.md index e115547..4aae3b5 100644 --- a/puppet/README.md +++ b/puppet/README.md @@ -9,9 +9,6 @@ The `executable_path` specifies the path to the Chromium binary for Puppeteer to ### Profile directory The `profile_dir` specifies which directory to put Chromium user data directories. -### URL -`url` specifies the URL of the index page of the LINE extension for your Chromium installation. - ### Extension directory The `extension_dir` specifies which directory contains the files for the LINE extension, which you must download yourself. diff --git a/puppet/example-config.json b/puppet/example-config.json index a814b2d..85f90c5 100644 --- a/puppet/example-config.json +++ b/puppet/example-config.json @@ -5,7 +5,6 @@ }, "executable_path": "", "profile_dir": "./profiles", - "url": "chrome-extension:///index.html", "extension_dir": "./extension_files", "cycle_delay": 5000, "use_xdotool": false, diff --git a/puppet/prep_helper.js b/puppet/prep_helper.js deleted file mode 100644 index 92ae681..0000000 --- a/puppet/prep_helper.js +++ /dev/null @@ -1,46 +0,0 @@ -// matrix-puppeteer-line - A very hacky Matrix-LINE bridge based on running LINE's Chrome extension in Puppeteer -// Copyright (C) 2020-2021 Tulir Asokan, Andrew Ferrazzutti -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -import puppeteer from "puppeteer" -import fs from "fs" - -import arg from "arg" - -const args = arg({ - "--config": String, - "--browser": String, - "-c": "--config", - "-b": "--browser", -}) - -const configPath = args["--config"] || "config.json" - -console.log("[Main] Reading config from", configPath) -const config = JSON.parse(fs.readFileSync(configPath).toString()) -const extensionDir = config.extension_dir || "extension_files" -const executablePath = args["--browser"] || config.executable_path; - -(async () => -{ - await puppeteer.launch({ - executablePath: executablePath, - headless: false, - args: [ - `--disable-extensions-except=${extensionDir}`, - `--load-extension=${extensionDir}` - ], - timeout: 0, - }) -})() diff --git a/puppet/src/main.js b/puppet/src/main.js index 7124ab6..c9542b9 100644 --- a/puppet/src/main.js +++ b/puppet/src/main.js @@ -37,7 +37,6 @@ MessagesPuppeteer.executablePath = args["--browser"] || config.executable_path | MessagesPuppeteer.noSandbox = args["--no-sandbox"] || MessagesPuppeteer.noSandbox MessagesPuppeteer.profileDir = config.profile_dir || MessagesPuppeteer.profileDir MessagesPuppeteer.devtools = config.devtools || false -MessagesPuppeteer.url = config.url MessagesPuppeteer.extensionDir = config.extension_dir || MessagesPuppeteer.extensionDir MessagesPuppeteer.cycleDelay = config.cycle_delay || MessagesPuppeteer.cycleDelay MessagesPuppeteer.useXdotool = config.use_xdotool || MessagesPuppeteer.useXdotool diff --git a/puppet/src/puppet.js b/puppet/src/puppet.js index ea218db..213273e 100644 --- a/puppet/src/puppet.js +++ b/puppet/src/puppet.js @@ -102,9 +102,18 @@ export default class MessagesPuppeteer { this.page = await this.browser.newPage() } - this.blankPage = await this.browser.newPage() - await this.page.bringToFront() + { + this.log("Finding extension UUID") + await this.page.goto("chrome://system") + const selector = "#extensions-value" + await this.page.waitForSelector(selector, 0) + const lineDetails = await this.page.$eval(selector, e => e.innerText) + const uuid = lineDetails.match(/(.*) : LINE : version/)[1] + this.log("Found extension UUID ${uuid}") + MessagesPuppeteer.url = `chrome-extension://${uuid}/index.html` + } + this.blankPage = await this.browser.newPage() if (MessagesPuppeteer.useXdotool) { this.log("Finding window ID") const buffer = execSync("xdotool search 'about:blank'")