I deleted it afterward
But it would be this code:
import { puppeteer } from '@pipedream/browsers';
import fs from "fs";
export default defineComponent({
key: "puppeteer-screenshot",
name: "Take a Screenshot",
version: "0.1.8",
type: "action",
props: {
puppeteer: {
type: "app",
app: "puppeteer",
},
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}}",
},
data: { type: "data_store" }
},
async run({ steps, $ }) {
const { filename } = this;
const { url } = this;
const browser = await puppeteer.browser();
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });
// Load the previously saved cookie.
const sessionidValue = await this.data.get("sessionid");
const cachecValue = await this.data.get("cachec");
const cookieSessionID = {
name: 'sessionid',
value: sessionidValue,
domain: '.[tradingview.com](http://tradingview.com)',
path: '/',
};
const cookieCachec = {
name: 'cachec',
value: cachecValue,
domain: '.[tradingview.com](http://tradingview.com)',
path: '/',
};
// Set the cookie on the page
await page.setCookie(cookieSessionID, cookieCachec);
// Configure the navigation timeout
await page.setDefaultNavigationTimeout(0);
await page.goto(url);
await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 100000 });
// await page.waitForTimeout(3000);
const elementChart = 'body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--center';
try {
// Wait until the element with the desired selector is loaded
await page.waitForSelector(elementChart, { timeout: 100000 }); // Timeout set in milliseconds
console.log('The elementChart is loaded.');
} catch (error) {
console.error('The elementChart was not found or did not load in time.');
}
const elementWidgetBar = 'body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--right > div > div.widgetbar-tabs > div > div > div > div > button.button-I_wb5FjE.isActive-I_wb5FjE.apply-common-tooltip.common-tooltip-vertical.accessible-I_wb5FjE';
// Check if the element is loaded and click on it.
try {
await page.waitForSelector(elementWidgetBar, { timeout: 5000 });
// If the element is available, click on it.
await page.click(elementWidgetBar);
console.log('Clicked on the element to hide the widgetbar');
} catch (error) {
console.log('The element to hide the widgetbar was not found or did not load in time. Action ignored.');
}
// Select element to screenshot
// const select = await page.$(elementChart)
// Screenshot
// await select.screenshot();
// const screenshot = await select.screenshot({ timeout: 0 });
console.log('Running the screenshot.');
const screenshot = await page.screenshot({
clip: { x: 56, y: 42, width: 1810, height: 995 }, timeout: 100000
});
console.log('Screenshot executed.');
await browser.close();
console.log('Browser closed.');
const fn = `${filename.replace(/[&\/\\#, +()$~%.'"":*?<>{}]/g, "-")}.png`;
fs.writeFileSync('/tmp/' + fn, screenshot)
$.export(
"filename", fn,
);
$.export(
"PathFL", "/tmp/" + fn
);
// return screenshot.toString('base64');
},
});