instauto 9.1.6 → 9.1.7

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 +13 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instauto",
3
- "version": "9.1.6",
3
+ "version": "9.1.7",
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
 
@@ -321,9 +324,15 @@ const Instauto = async (db, browser, options) => {
321
324
  const elementHandles3 = await page.$x("//header//button[*//span[@aria-label='Following']]");
322
325
  if (elementHandles3.length > 0) return elementHandles3[0];
323
326
 
324
- const elementHandles4 = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Following']]");
327
+ const elementHandles4 = await page.$x("//header//button[*//span[@aria-label='Requested']]");
325
328
  if (elementHandles4.length > 0) return elementHandles4[0];
326
329
 
330
+ const elementHandles5 = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Following']]");
331
+ if (elementHandles5.length > 0) return elementHandles5[0];
332
+
333
+ const elementHandles6 = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Requested']]");
334
+ if (elementHandles6.length > 0) return elementHandles6[0];
335
+
327
336
  return undefined;
328
337
  }
329
338
 
@@ -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
  }