Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
puppeteer page navigation issues with heroku deployment

I am using TD Ameritrade's API and am trying to implement an automated work flow for the access token refresh process. I have chosen to use the npm package "puppeteer" to programmatically login to the TD Ameritrade developer website and retrieve my code(a long string that needs to be URL decoded needed for the access token refresh process) from a URI that the bot gets redirected to after logging in and accepting the terms for further permissions to access my trading account.

Everything worked fine on my end, but when I deployed my code to heroku the redirect to the URI does not happen and I am only able to grab the URL of the site I was on before the redirect to the URI.

Here is my code:

const getTdAmeritradeCode = async () => {
    const browser = await puppeteer.launch({
        headless: true,
        args: ['--no-sandbox','--disable-setuid-sandbox']
    });

    const page = await browser.newPage();
    await page.goto(process.env.REFRESH_TOKEN_REFRESH_LINK);
    await page.type("#username0", process.env.TD_AMERITRADE_USERNAME);
    await page.type("#password1", process.env.TD_AMERITRADE_PASSWORD);
    const [response0] = await Promise.all([
        page.waitForNavigation(),
        page.click("#accept"),
    ]);
    const [response1] = await Promise.all([
        page.waitForNavigation(),
        page.click("#accept"),
    ]);

    let tdAmeritradeCode = decode(await page.url().slice(50)); // 50 is the number of characters in the url before the code
    await browser.close();
    return tdAmeritradeCode;
}

That is the method I have found on the puppeteer documentation, but it does not seem to be working. Like I said earlier, the code works as intended on my machine but when deployed on heroku the code fails the response1 Promise and does not get redirected to the URI.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The issue was I had my TD Ameritrade application redirect to my Heroku application's URL. I believe it's due to the fact that Heroku applications are not meant to make a GET request to themselves. I ended up changing the redirect URI in my TD Ameritrade and Heroku applications and I was able to get the code without problem.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!