Skip to content

Commit 6e6df12

Browse files
authored
Version 1.0.6
Fixed bugs logging in, creating Applets, and archiving Applets because of changes on IFTTT’s website.
1 parent f60efb6 commit 6e6df12

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The `broadlink-webhooks` package is published through [npm](https://www.npmjs.co
2828

2929
*Please note, if you do not install "globally" (using the "-g" flag) as shown in the installation command above, the `broadlink-webhooks` command will not be available to run in your Terminal or Command window because of `npm`'s installation behavior.*
3030

31-
After you've installed `broadlink-webhooks`, you'll also need to install a WebDriver executable for your web browser of choice. `broadlink-webhooks` has been tested with and has menu options for Firefox, Chrome. I have not bothered testing or adding menu options for any other web browsers, such as Edge. Safari was previously supported on macOS, but support was removed for Safari in version 1.0.5 since it was not performing reliably when automated with the latest version of the IFTTT website and was not proving to be worth the extra development and testing effort. As of August 2021, I've tested `broadlink-webhooks` on macOS 11 Big Sur, Windows 10 (May 2021 Update, 21H1), and Linux Mint 20.2 Uma using the latest versions of Firefox and Chrome on all OSes.
31+
After you've installed `broadlink-webhooks`, you'll also need to install a WebDriver executable for your web browser of choice. `broadlink-webhooks` has been tested with and has menu options for Firefox and Chrome. I have not bothered testing or adding menu options for any other web browsers, such as Edge. Safari was previously supported on macOS, but support was removed for Safari in version 1.0.5 since it was not performing reliably when automated with the latest version of the IFTTT website and was not proving to be worth the extra development and testing effort. As of August 2021, I've tested `broadlink-webhooks` on macOS 11 Big Sur, Windows 10 (May 2021 Update, 21H1), and Linux Mint 20.2 Uma using the latest versions of Firefox and Chrome on all OSes.
3232

3333
For Firefox and/or Chrome, you will need to download and install their WebDriver executables manually:
3434

broadlink-webhooks.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ let browserToAutomate = null;
205205

206206
needNewWebDriver = false;
207207

208-
await webDriver.get(iftttLogInURL);
208+
await webDriver.get('https://ifttt.com/my_services'); // This URL will forward to https://ifttt.com/join if not logged in.
209209

210210
try {
211211
await webDriver.switchTo().alert().accept(); // There could be a Leave Page confirmation that needs to be accepted on Chrome (but it doesn't hurt to also check on Firefox).
@@ -214,7 +214,7 @@ let browserToAutomate = null;
214214
// Ignore any error if there is no Leave Page confirmation.
215215
}
216216

217-
if ((await webDriver.getCurrentUrl()) == iftttLogInURL) throw 'NEED TO RE-LOG IN';
217+
if ((await webDriver.getCurrentUrl()) == 'https://ifttt.com/join') throw 'NEED TO RE-LOG IN';
218218
} catch (checkForLogInError) {
219219
let logInMethodPromptResponse = await prompts([
220220
{
@@ -398,8 +398,7 @@ let browserToAutomate = null;
398398

399399
let currentURL = await webDriver.getCurrentUrl();
400400

401-
// IFTTT will first redirect to "https://ifttt.com/session" and then finally to "https://ifttt.com/home" after successfully logging in.
402-
while (currentURL != 'https://ifttt.com/home') {
401+
while (currentURL.startsWith('https://ifttt.com/login') || currentURL == 'https://ifttt.com/session') {
403402
if (currentURL == iftttLogInURL) {
404403
try {
405404
await webDriver.wait(
@@ -488,7 +487,7 @@ let browserToAutomate = null;
488487
} else {
489488
for ( ; ; ) {
490489
try {
491-
await webDriver.get(iftttLogInURL);
490+
await webDriver.get('https://ifttt.com/my_services'); // This URL will forward to https://ifttt.com/join if not logged in.
492491

493492
try {
494493
await webDriver.switchTo().alert().accept(); // There could be a Leave Page confirmation that needs to be accepted on Chrome (but it doesn't hurt to also check on Firefox).
@@ -497,14 +496,13 @@ let browserToAutomate = null;
497496
// Ignore any error if there is no Leave Page confirmation.
498497
}
499498

500-
let currentURL = await webDriver.getCurrentUrl();
501-
502-
if (currentURL == 'https://ifttt.com/home') {
499+
if ((await webDriver.getCurrentUrl()) != 'https://ifttt.com/join') {
503500
lastIFTTTusernameUsed = 'loggedInManuallyViaWebBrowser';
504501
lastIFTTTpasswordUsed = null;
505502

506503
break;
507504
} else {
505+
await webDriver.get(iftttLogInURL);
508506
throw 'NEED TO LOG IN';
509507
}
510508
} catch (checkForLogInError) {
@@ -591,6 +589,8 @@ let browserToAutomate = null;
591589
console.info(`\nIFTTT Webhooks Key: ${iftttWebhooksKey}`);
592590
}
593591

592+
console.info('\nDetecting Existing Webhooks Applets...');
593+
594594
let existingWebhooksBroadLinkAppletIDsAndNames = {};
595595
let allowedWebhooksBroadLinkAppletNamePrefixes = [];
596596

@@ -746,6 +746,8 @@ let browserToAutomate = null;
746746
let currentBroadLinkSceneNamesArray = [];
747747

748748
if ((optionsPromptsResponse.taskSelection == taskCreateApplets) || (optionsPromptsResponse.taskSelection == taskArchiveAppletsNotInBroadLink) || (optionsPromptsResponse.taskSelection == taskOutputSummary)) {
749+
console.info('\nDetecting BroadLink Devices & Scenes...');
750+
749751
for (let retrieveDevicesAndScenesAttemptCount = 1; retrieveDevicesAndScenesAttemptCount <= maxTaskAttempts; retrieveDevicesAndScenesAttemptCount ++) {
750752
try {
751753
await setup_ifttt_webhooks_broadlink_applet('FakeEventName-ToRetrieveRealDeviceAndSceneNames', (optionsPromptsResponse.groupSelection == groupScenesOnly));
@@ -917,19 +919,24 @@ let browserToAutomate = null;
917919
await webDriver.wait(
918920
until.elementLocated(By.xpath('//textarea[@name="description"]')), longWaitForElementTime
919921
).then(async thisElement => {
920-
originalAppletTitle = await thisElement.getText();
921-
922-
if (originalAppletTitle != correctOriginalAppletTitle) {
923-
throw `ORIGINAL APPLET TITLE NOT CORRECT ("${originalAppletTitle}" != "${correctOriginalAppletTitle}")`;
924-
}
925-
926-
await thisElement.clear();
927-
await thisElement.sendKeys(Key.ENTER, Key.BACK_SPACE); // Send Enter and then Backspace keys be sure the contents get updated, because the character count doesn't always get updated when only using clear().
928-
await thisElement.clear(); // clear() again after that to be sure the title field is empty.
929-
930-
await thisElement.sendKeys(desiredAppletTitle);
931-
932-
console.info(`\tOriginal Applet Title: ${originalAppletTitle}`);
922+
await webDriver.wait(
923+
until.elementLocated(By.xpath('//textarea[@name="description"]/following-sibling::div')), shortWaitForElementTime
924+
).then(async thatElement => {
925+
// Cannot get the originalAppletTitle from the actual textarea, but can get it from the div right after it.
926+
originalAppletTitle = (await thatElement.getAttribute('innerHTML')).trim(); // getText() doesn't work here for some reason. (Need to trim since there will be a trailing line break.)
927+
928+
if (originalAppletTitle != correctOriginalAppletTitle) {
929+
throw `ORIGINAL APPLET TITLE NOT CORRECT ("${originalAppletTitle}" != "${correctOriginalAppletTitle}")`;
930+
}
931+
932+
await thisElement.clear();
933+
await thisElement.sendKeys(Key.ENTER, Key.BACK_SPACE); // Send Enter and then Backspace keys be sure the contents get updated, because the character count doesn't always get updated when only using clear().
934+
await thisElement.clear(); // clear() again after that to be sure the title field is empty.
935+
936+
await thisElement.sendKeys(desiredAppletTitle);
937+
938+
console.info(`\tOriginal Applet Title: ${originalAppletTitle}`);
939+
});
933940
});
934941

935942
// Applets notifications are disabled by default now, but still check just in case.
@@ -1007,7 +1014,16 @@ let browserToAutomate = null;
10071014
currentURL = await webDriver.getCurrentUrl();
10081015

10091016
if (currentURL.startsWith('https://ifttt.com/applets/')) {
1010-
console.info(`\tEdit Applet URL: ${currentURL}/edit`);
1017+
try {
1018+
await webDriver.wait(
1019+
until.elementLocated(By.xpath('//div[contains(@class,"connection-settings-btn")]/a')), shortWaitForElementTime
1020+
).then(async thisElement => {
1021+
var thisEditAppletURL = await thisElement.getAttribute('href');
1022+
console.info(`\tEdit Applet URL: ${thisEditAppletURL}`);
1023+
});
1024+
} catch (retrieveEditURLError) {
1025+
console.info(`\tEdit Applet URL: ${currentURL}/edit`);
1026+
}
10111027

10121028
let finalAppletTitle = 'FAILED_TO_RETRIEVE_FINAL_APPLET_TITLE';
10131029
let failedToRetrieveFinalAppletTitleCount = 0;
@@ -1137,7 +1153,7 @@ let browserToAutomate = null;
11371153
await webDriver.switchTo().alert().accept();
11381154

11391155
let currentURL = await webDriver.getCurrentUrl();
1140-
while ((currentURL != 'https://ifttt.com/home') && (currentURL != 'https://ifttt.com')) { // Could end up at either of these URLs after archiving an applet.
1156+
while ((currentURL != 'https://ifttt.com/explore') && (currentURL != 'https://ifttt.com/')) { // Could end up at either of these URLs after archiving an applet.
11411157
currentURL = await webDriver.getCurrentUrl();
11421158
await webDriver.sleep(waitForNextPageSleepInLoopTime);
11431159
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "broadlink-webhooks",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Create and Manage IFTTT Webhooks Applets for BroadLink (Using Selenium WebDriver)",
55
"main": "broadlink-webhooks.js",
66
"bin": {
@@ -41,8 +41,8 @@
4141
"Scene"
4242
],
4343
"dependencies": {
44-
"selenium-webdriver": "^4.0.0-beta.4",
45-
"prompts": "^2.4.1",
44+
"selenium-webdriver": "^4.1.1",
45+
"prompts": "^2.4.2",
4646
"sanitize-filename": "^1.6.3"
4747
},
4848
"author": "RandomApplications",

0 commit comments

Comments
 (0)