From 874fb375d99dc8c5358fa5cf211c56be4e3d2d26 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Thu, 11 Feb 2021 00:04:25 -0500 Subject: [PATCH] Fix some more login problems --- puppet/src/contentscript.js | 4 ++-- puppet/src/puppet.js | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/puppet/src/contentscript.js b/puppet/src/contentscript.js index 7d31d3e..9996236 100644 --- a/puppet/src/contentscript.js +++ b/puppet/src/contentscript.js @@ -413,8 +413,8 @@ class MautrixController { this.emailAppearObserver = new MutationObserver(changes => { for (const change of changes) { for (const node of change.addedNodes) { - const emailElement = node.querySelector("#login_email_btn") - if (emailElement) { + const emailArea = node.querySelector("#login_email_area") + if (emailArea && !emailArea.getAttribute("class").includes("MdNonDisp")) { window.__mautrixSendEmailCredentials() return } diff --git a/puppet/src/puppet.js b/puppet/src/puppet.js index fa31b1c..843392f 100644 --- a/puppet/src/puppet.js +++ b/puppet/src/puppet.js @@ -157,10 +157,10 @@ export default class MessagesPuppeteer { const emailButton = await this.page.waitForSelector("#login_email_btn") await emailButton.click() - const emailArea = await this.page.waitForSelector("#login_email_area", {visible: true}) + await this.page.waitForSelector("#login_email_area", {visible: true}) this.login_email = login_data["email"] this.login_password = login_data["password"] - this._sendEmailCredentials() + await this._sendEmailCredentials() await this.page.evaluate( element => window.__mautrixController.addEmailAppearObserver(element), loginContentArea) @@ -202,12 +202,12 @@ export default class MessagesPuppeteer { const result = await Promise.race([ () => this.page.waitForSelector("#wrap_message_sync", {timeout: 2000}) - .then(element => { + .then(value => { loginSuccess = true - return element + return value }), () => this.page.waitForSelector("#login_incorrect", {visible: true, timeout: 2000}) - .then(element => element.innerText), + .then(value => this.page.evaluate(element => element.innerText, value)), () => this._waitForLoginCancel(), ].map(promiseFn => cancelableResolve(promiseFn))) @@ -490,13 +490,16 @@ export default class MessagesPuppeteer { async _sendEmailCredentials() { this.log("Inputting login credentials") - // Triple-click email input field to select all existing text and replace it on type - const emailInput = await this.page.$("#line_login_email") - await emailInput.click({clickCount: 3}) - await emailInput.type(this.login_email) + // Triple-click input fields to select all existing text and replace it on type + let input - // Password input field always starts empty, so no need to select its text first - await this.page.type("#line_login_pwd", this.login_password) + input = await this.page.$("#line_login_email") + await input.click({clickCount: 3}) + await input.type(this.login_email) + + input = await this.page.$("#line_login_pwd") + await input.click({clickCount: 3}) + await input.type(this.login_password) await this.page.click("button#login_btn") }