0

I'm trying to make a function that can loop through Instagram photos and like them one by one but I couldn't figure out the syntax error I got.

likeTagsProcess = async (tags = []) => {
    for (let tag of tags) {

        // Go to the hashtag page
        await instagram.page.goto(TAG_URL(tag), {
            waitUntil: 'networkidle2'
        });

        await instagram.page.waitFor(1000);

        let posts = await instagram.page.$$('article > div:nth-child(3) img[decoding="auto"]');

        for (let i = 0; i < 3; i++) {

            let post = posts[i];

            // Click on the post
            await post.click();

            // Wait for the modal to appear
            await instagram.page.waitFor('span[id="react-root"][arria-hidden="true"]');
            await instagram.page.waitFor(1000);


            // Liking Posts
            let isLikable = await instagram.page.$('span[aria-label="Like"]');

            if (isLikable) {

            // Clicking Like
            await instagram.page.click('span[aria-label="Like"]');

            }

            await instagram.page.waitFor(2500);

            // Close the modal 


            await instagram.page.click("body > div._2dDPU.CkGkG > div.Igw0E.IwRSH.eGOV_._4EzTm.BI4qX.qJPeX.fm1AK.TxciK.yiMZG > button > svg");
            await instagram.page.waitFor(1000);
        }

        await instagram.page.waitFor(10000);

    }
}

typescript throws this error:

Syntax Error : likeTagsProcess = async (tags = []) => {
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid shorthand property initializer
3
  • Off-topic: you seem to have misspelled aria-hidden to arria-hidden. Commented Apr 10, 2020 at 20:01
  • You may need to show some context. Could it be that the whole likeTagsProcess = ... assignment is part of an even bigger object initializer? That would explain the error... Commented Apr 10, 2020 at 20:28
  • @RuudHelderman No, I didn't have any bigger object initializer. the problem was to add const : to the LikeTagsProcess. Commented Apr 10, 2020 at 20:38

3 Answers 3

1

To declare a function with the ES6 "fat-arrow", you have to do this:

//note the "const" before the function name
const likeTagsProcess = async (tags = []) => {
   //do whatever you want to do
}

You can find more information here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Sign up to request clarification or add additional context in comments.

Comments

0

I added const: and it worked properly thank you guys.

` const : likeTagsProcess = async (tags = []) => {...}

`

Comments

0

It looks like likeTagsProcess is an object project and should be defined using { key: value }.

So you code should look like this

const someObject = {
  likeTagsProcess: async (tags = []) => {
    for (let tag of tags) {

      // Go to the hashtag page
      await instagram.page.goto(TAG_URL(tag), {
        waitUntil: 'networkidle2'
      });

      await instagram.page.waitFor(1000);

      let posts = await instagram.page.$$('article > div:nth-child(3) img[decoding="auto"]');

      for (let i = 0; i < 3; i++) {

        let post = posts[i];

        // Click on the post
        await post.click();

        // Wait for the modal to appear
        await instagram.page.waitFor('span[id="react-root"][arria-hidden="true"]');
        await instagram.page.waitFor(1000);


        // Liking Posts
        let isLikable = await instagram.page.$('span[aria-label="Like"]');

        if (isLikable) {

          // Clicking Like
          await instagram.page.click('span[aria-label="Like"]');

        }

        await instagram.page.waitFor(2500);

        // Close the modal 


        await instagram.page.click("body > div._2dDPU.CkGkG > div.Igw0E.IwRSH.eGOV_._4EzTm.BI4qX.qJPeX.fm1AK.TxciK.yiMZG > button > svg");
        await instagram.page.waitFor(1000);
      }

      await instagram.page.waitFor(10000);

    }
  }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.