Add flag to set browser executable path
This commit is contained in:
parent
ccf7e25f46
commit
03e8090cd1
@ -11,4 +11,4 @@ COPY package.json yarn.lock ./
|
||||
RUN yarn --production && rm -rf node_modules/puppeteer/.local-chromium
|
||||
|
||||
COPY . /opt/mautrix-amp/puppet
|
||||
CMD ["yarn", "start", "/data/config.json"]
|
||||
CMD ["yarn", "start", "--config", "/data/config.json", "--browser", "/usr/lib/chromium/chrome"]
|
||||
|
@ -3,5 +3,7 @@
|
||||
"type": "unix",
|
||||
"path": "/var/run/mautrix-amp/puppet.sock"
|
||||
},
|
||||
"profile_dir": "./profiles"
|
||||
"profile_dir": "./profiles",
|
||||
"disable_debug": true,
|
||||
"url": "https://messages.google.com/web/",
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
"start": "node ./src/main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"arg": "^4.1.3",
|
||||
"chrono-node": "^2.1.7",
|
||||
"puppeteer": "5.1.0"
|
||||
},
|
||||
|
@ -16,16 +16,26 @@
|
||||
import process from "process"
|
||||
import fs from "fs"
|
||||
|
||||
import arg from "arg"
|
||||
|
||||
import PuppetAPI from "./api.js"
|
||||
import MessagesPuppeteer from "./puppet.js"
|
||||
|
||||
let path = process.argv[process.argv.length - 1]
|
||||
if (!path.endsWith(".json")) {
|
||||
path = "config.json"
|
||||
}
|
||||
console.log("Reading config from", path)
|
||||
const config = JSON.parse(fs.readFileSync(path).toString())
|
||||
MessagesPuppeteer.profileDir = config.profile_dir
|
||||
const args = arg({
|
||||
"--config": String,
|
||||
"--browser": String,
|
||||
"-c": "--config",
|
||||
"-b": "--browser",
|
||||
})
|
||||
|
||||
const configPath = args["--config"] || "config.json"
|
||||
MessagesPuppeteer.executablePath = args["--browser"] || MessagesPuppeteer.executablePath
|
||||
|
||||
console.log("Reading config from", configPath)
|
||||
const config = JSON.parse(fs.readFileSync(configPath).toString())
|
||||
MessagesPuppeteer.profileDir = config.profile_dir || MessagesPuppeteer.profileDir
|
||||
MessagesPuppeteer.disableDebug = !!config.disable_debug
|
||||
MessagesPuppeteer.url = config.url || MessagesPuppeteer.url
|
||||
|
||||
const api = new PuppetAPI(config.listen)
|
||||
|
||||
|
@ -24,7 +24,10 @@ import { sleep } from "./util.js"
|
||||
|
||||
export default class MessagesPuppeteer {
|
||||
static profileDir = "./profiles"
|
||||
url = "https://messages.google.com/web/"
|
||||
static executablePath = undefined
|
||||
static disableDebug = false
|
||||
static viewport = { width: 1920, height: 1080 }
|
||||
static url = "https://messages.google.com/web/"
|
||||
|
||||
/**
|
||||
*
|
||||
@ -59,9 +62,10 @@ export default class MessagesPuppeteer {
|
||||
async start(debug = false) {
|
||||
this.log("Launching browser")
|
||||
this.browser = await puppeteer.launch({
|
||||
executablePath: MessagesPuppeteer.executablePath,
|
||||
userDataDir: this.profilePath,
|
||||
headless: !debug,
|
||||
defaultViewport: { width: 1920, height: 1080 },
|
||||
headless: MessagesPuppeteer.disableDebug || !debug,
|
||||
defaultViewport: MessagesPuppeteer.viewport,
|
||||
})
|
||||
this.log("Opening new tab")
|
||||
const pages = await this.browser.pages()
|
||||
@ -70,8 +74,8 @@ export default class MessagesPuppeteer {
|
||||
} else {
|
||||
this.page = await this.browser.newPage()
|
||||
}
|
||||
this.log("Opening", this.url)
|
||||
await this.page.goto(this.url)
|
||||
this.log("Opening", MessagesPuppeteer.url)
|
||||
await this.page.goto(MessagesPuppeteer.url)
|
||||
|
||||
this.log("Injecting content script")
|
||||
await this.page.addScriptTag({ path: "./src/contentscript.js", type: "module" })
|
||||
|
@ -170,6 +170,11 @@ ansi-styles@^4.1.0:
|
||||
"@types/color-name" "^1.1.1"
|
||||
color-convert "^2.0.1"
|
||||
|
||||
arg@^4.1.3:
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
||||
|
||||
argparse@^1.0.7:
|
||||
version "1.0.10"
|
||||
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
|
||||
|
Loading…
Reference in New Issue
Block a user