Auto-derive the installed LINE extension's UUID

This commit is contained in:
Andrew Ferrazzutti 2021-07-08 02:08:20 -04:00
parent 975e9c5369
commit 570eedf904
6 changed files with 12 additions and 58 deletions

View File

@ -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`

View File

@ -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.

View File

@ -5,7 +5,6 @@
},
"executable_path": "",
"profile_dir": "./profiles",
"url": "chrome-extension://<extension-uuid>/index.html",
"extension_dir": "./extension_files",
"cycle_delay": 5000,
"use_xdotool": false,

View File

@ -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 <https://www.gnu.org/licenses/>.
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,
})
})()

View File

@ -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

View File

@ -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'")