forked from fair/matrix-puppeteer-line
Fix outbound message sending
The message text input field in LINE chats doesn't play nice with Puppeteer's "type" function for live-typing text... It's a div instead of a text input, and uses innerText instead of value. Setting its innerText directly seems to work best, so just use that.
This commit is contained in:
parent
8fb0e2a101
commit
0d154c826e
|
@ -128,6 +128,18 @@ export default class MessagesPuppeteer {
|
||||||
await this.page.addScriptTag({ path: "./src/contentscript.js", type: "module" })
|
await this.page.addScriptTag({ path: "./src/contentscript.js", type: "module" })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the contents of a text input field to the given text.
|
||||||
|
* Works by triple-clicking the input field to select all existing text, to replace it on type.
|
||||||
|
*
|
||||||
|
* @param {ElementHandle} inputElement - The input element to type into.
|
||||||
|
* @param {string} text - The text to input.
|
||||||
|
*/
|
||||||
|
async _enterText(inputElement, text) {
|
||||||
|
await inputElement.click({clickCount: 3})
|
||||||
|
await inputElement.type(text)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait for the session to be logged in and monitor changes while it's not.
|
* Wait for the session to be logged in and monitor changes while it's not.
|
||||||
*/
|
*/
|
||||||
|
@ -557,8 +569,11 @@ export default class MessagesPuppeteer {
|
||||||
() => window.__mautrixController.promiseOwnMessage(5000, "time"))
|
() => window.__mautrixController.promiseOwnMessage(5000, "time"))
|
||||||
|
|
||||||
const input = await this.page.$("#_chat_room_input")
|
const input = await this.page.$("#_chat_room_input")
|
||||||
|
// Live-typing in the field can have its text mismatch what was requested!!
|
||||||
|
// Probably because the input element is a div instead of a real text input...ugh!
|
||||||
|
// Setting its innerText directly works fine though...
|
||||||
await input.click()
|
await input.click()
|
||||||
await input.type(text)
|
await input.evaluate((e, text) => e.innerText = text, text)
|
||||||
await input.press("Enter")
|
await input.press("Enter")
|
||||||
|
|
||||||
return await this._waitForSentMessage(chatID)
|
return await this._waitForSentMessage(chatID)
|
||||||
|
@ -724,18 +739,8 @@ export default class MessagesPuppeteer {
|
||||||
|
|
||||||
async _sendEmailCredentials() {
|
async _sendEmailCredentials() {
|
||||||
this.log("Inputting login credentials")
|
this.log("Inputting login credentials")
|
||||||
|
await this._enterText(await this.page.$("#line_login_email"), this.login_email)
|
||||||
// Triple-click input fields to select all existing text and replace it on type
|
await this._enterText(await this.page.$("#line_login_pwd"), this.login_password)
|
||||||
let input
|
|
||||||
|
|
||||||
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")
|
await this.page.click("button#login_btn")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue