Timeout Error in Browserless Step: How to Resolve?

This topic was automatically generated from Slack. You can find the original thread here.

I’m getting “TIMEOUT” error in a browserless step. Can you help me?

I’m sorry to hear that you’re experiencing a timeout error with Browserless. To better assist you, could you please provide more information about the specific Browserless action you’re using and any relevant details about your workflow? This will help me understand the issue and offer a solution.

I’m using browserless_take_screenshot

It seems like you’re using the Browserless Take Screenshot action. If you’re experiencing a timeout error, it could be due to a slow-loading website or a large page size. To help you further, could you please provide more information about the URL you’re trying to capture and any additional settings you’ve configured in the action? This will help me identify the issue and suggest a solution.

one of the sites would be “Live stock, index, futures, Forex and Bitcoin charts on TradingView

And I’m using the following code:

// legacy_hash_id: a_oViVKv
import puppeteer from "puppeteer-core@20.4.0";

export default {
  key: "browserless-take-screenshot",
  name: "Take a Screenshot",
  version: "0.5.4",
  type: "action",
  props: {
    browserless: {
      type: "app",
      app: "browserless",
    },
    url: {
      type: "string",
      label: "URL",
      description: "Enter the URL you'd like to take a screenshot of here",
      default: "{{steps.data_processing_discord.URL}}",
    },
    filename: {
      type: "string",
      label: "Name File",
      description: "Enter the filename",
      default: "{{steps.data_processing_discord[\"Source+Symbol\"]}}-{{steps.data_processing_discord.Data}}",
    },
    operation_type: {
            type: "string",
            label: "Operation Type",
            default: "{{steps.data_processing_discord[\"Operation Type\"]}}",
    }
  },
  async run({ $ }) {
    const operation_type = this.operation_type
    
    if (operation_type == "swingtrade") {

      const browser = await puppeteer.connect({
        browserWSEndpoint: `wss://chrome.browserless.io?token=${this.browserless.$auth.api_key}`,
      });
      const page = await browser.newPage();

      const { filename } = this;
      const { url } = this;
      await page.setViewport({ width: 1920, height: 1080 });
      await page.goto(url);

      // Hide widgetbar
      /**await page.evaluate(()=>{
        var rightpanel = document.querySelector(".widgetbar-tabs");
        rightpanel.parentNode.removeChild(rightpanel);
      });**/
      // await page.waitForSelector('body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--right > div > div.widgetbar-tabs > div > div > div > div > div:nth-child(1)')
      // await page.click('body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--right > div > div.widgetbar-tabs > div > div > div > div > div:nth-child(1)')
      
      // Select element to screenshot
      await page.waitForSelector('body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--center')
      const select = await page.$('body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--center')
      
      // Screenshot
      await select.screenshot();
      const screenshot = await select.screenshot();


      // export the base64-encoded screenshot for use in future steps,
      // along with the image type and filename
      $.export("screenshot", Buffer.from(screenshot, "binary").toString("base64"));
      $.export("type", "png");
      $.export(
        "filename",
        `${filename.replace(/[&\/\\#, +()$~%.'"":*?<>{}]/g, "-")}.png`,
      );

      await browser.close();
    }
  },
};

It looks like you’re using the Browserless app to take a screenshot of the TradingView chart. Your code seems to be set up correctly for connecting to Browserless and taking a screenshot. If you’re facing any issues or need further assistance, please let me know.