Just to signal how I solved it.
I assembled the following code. I still have a problem because it’s not loading all indicators in the layout for not being logged in.
code to take the screenshot
// legacy_hash_id: a_oViVKv
import puppeteer from "puppeteer-core";
export default {
key: "browserless-take-screenshot",
name: "Take a Screenshot",
version: "0.5.1",
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",
},
filename: {
type: "string",
label: "Name File",
description: "Enter the filename",
}
},
async run({ $ }) {
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.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
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();
},
};
code to save the screenshot
import fs from "fs"
export default defineComponent({
async run({ steps, $ }) {
const data = steps.take_screenshot.screenshot
// base64 data to buffer
var buffer = Buffer.from(data,'base64')
// buffer to image
fs.writeFileSync('/tmp/' + steps.take_screenshot.filename, buffer)
}
});
I need to configure a tradingview login, but I use google login + 2FA and I’m looking for a solution, otherwise, I’ll have to change the tradingview login to common login and password.
Thanks for your answers.
