instauto 9.1.5 → 9.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +20 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instauto",
3
- "version": "9.1.5",
3
+ "version": "9.1.8",
4
4
  "description": "Instagram automation library written in Node.js",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -170,11 +170,14 @@ const Instauto = async (db, browser, options) => {
170
170
  return new Date().getTime() - followedUserEntry.time < dontUnfollowUntilTimeElapsed;
171
171
  }
172
172
 
173
+ // See https://github.com/mifi/SimpleInstaBot/issues/140#issuecomment-1149105387
174
+ const gotoUrl = async (url) => page.goto(url, { waitUntil: ['load', 'domcontentloaded', 'networkidle0'] });
175
+
173
176
  async function gotoWithRetry(url) {
174
177
  const maxAttempts = 3;
175
178
  for (let attempt = 0; ; attempt += 1) {
176
179
  logger.log(`Goto ${url}`);
177
- const response = await page.goto(url);
180
+ const response = await gotoUrl(url);
178
181
  await sleep(2000);
179
182
  const status = response.status();
180
183
 
@@ -312,17 +315,23 @@ const Instauto = async (db, browser, options) => {
312
315
  }
313
316
 
314
317
  async function findUnfollowButton() {
315
- const elementHandles = await page.$x("//header//button[text()='Following']");
318
+ let button = await findButtonWithText('Following');
319
+ if (button) return button;
320
+
321
+ button = await findButtonWithText('Requested');
322
+ if (button) return button;
323
+
324
+ let elementHandles = await page.$x("//header//button[*//span[@aria-label='Following']]");
316
325
  if (elementHandles.length > 0) return elementHandles[0];
317
326
 
318
- const elementHandles2 = await page.$x("//header//button[text()='Requested']");
319
- if (elementHandles2.length > 0) return elementHandles2[0];
327
+ elementHandles = await page.$x("//header//button[*//span[@aria-label='Requested']]");
328
+ if (elementHandles.length > 0) return elementHandles[0];
320
329
 
321
- const elementHandles3 = await page.$x("//header//button[*//span[@aria-label='Following']]");
322
- if (elementHandles3.length > 0) return elementHandles3[0];
330
+ elementHandles = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Following']]");
331
+ if (elementHandles.length > 0) return elementHandles[0];
323
332
 
324
- const elementHandles4 = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Following']]");
325
- if (elementHandles4.length > 0) return elementHandles4[0];
333
+ elementHandles = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Requested']]");
334
+ if (elementHandles.length > 0) return elementHandles[0];
326
335
 
327
336
  return undefined;
328
337
  }
@@ -553,7 +562,7 @@ const Instauto = async (db, browser, options) => {
553
562
 
554
563
  await window.instautoSleep(3000);
555
564
 
556
- const closeButtonChild = document.querySelector('button [aria-label=Close]');
565
+ const closeButtonChild = document.querySelector('svg[aria-label="Close"]');
557
566
 
558
567
  if (!closeButtonChild) throw new Error('Close button not found (aria-label)');
559
568
 
@@ -795,7 +804,7 @@ const Instauto = async (db, browser, options) => {
795
804
 
796
805
  if (enableCookies) await tryLoadCookies();
797
806
 
798
- const goHome = async () => page.goto(`${instagramBaseUrl}/?hl=en`);
807
+ const goHome = async () => gotoUrl(`${instagramBaseUrl}/?hl=en`);
799
808
 
800
809
  // https://github.com/mifi/SimpleInstaBot/issues/28
801
810
  async function setLang(short, long, assumeLoggedIn = false) {
@@ -807,7 +816,7 @@ const Instauto = async (db, browser, options) => {
807
816
  // when logged in, we need to go to account in order to be able to check/set language
808
817
  // (need to see the footer)
809
818
  if (assumeLoggedIn) {
810
- await page.goto(`${instagramBaseUrl}/accounts/edit/`);
819
+ await gotoUrl(`${instagramBaseUrl}/accounts/edit/`);
811
820
  } else {
812
821
  await goHome();
813
822
  }