diff --git a/components/browserless/actions/convert-html-to-pdf/convert-html-to-pdf.mjs b/components/browserless/actions/convert-html-to-pdf/convert-html-to-pdf.mjs index c1dedb586a5b8..0ab254ebeaced 100644 --- a/components/browserless/actions/convert-html-to-pdf/convert-html-to-pdf.mjs +++ b/components/browserless/actions/convert-html-to-pdf/convert-html-to-pdf.mjs @@ -1,44 +1,63 @@ -// legacy_hash_id: a_B0ip1E -import { axios } from "@pipedream/platform"; +import browserless from "../../browserless.app.mjs"; +import fs from "fs"; export default { key: "browserless-convert-html-to-pdf", name: "Generate PDF from HTML String", description: "See https://docs.browserless.io/docs/pdf.html", - version: "0.4.1", + version: "0.4.2", type: "action", props: { - browserless: { - type: "app", - app: "browserless", - }, + browserless, html: { type: "string", label: "HTML String", description: "HTML to render as a PDF", }, + downloadPath: { + type: "string", + label: "Download Path", + description: "Download the screenshot to the `/tmp` directory with the specified filename", + optional: true, + }, + syncDir: { + type: "dir", + accessMode: "write", + sync: true, + }, + }, + methods: { + async downloadToTMP(screenshot) { + const path = this.downloadPath.includes("/tmp") + ? this.downloadPath + : `/tmp/${this.downloadPath}`; + fs.writeFileSync(path, screenshot); + return path; + }, }, async run({ $ }) { const { html } = this; - const data = await axios($, { - method: "POST", - url: `https://chrome.browserless.io/pdf?token=${this.browserless.$auth.api_key}`, - headers: { - "Cache-Control": "no-cache", - "Content-Type": "application/json", - }, - responseType: "arraybuffer", + const data = await this.browserless.convertHtmlToPdf({ + $, data: { html, - options: { - displayHeaderFooter: true, - printBackground: false, - format: "Letter", - }, }, }); - $.export("pdf", Buffer.from(data, "binary").toString("base64")); + const result = { + pdf: Buffer.from(data, "binary").toString("base64"), + }; + + if (data && this.downloadPath) { + const filePath = await this.downloadToTMP(data); + result.filePath = filePath; + } + + if (data) { + $.export("$summary", "Successfully generated PDF from HTML string."); + } + + return result; }, }; diff --git a/components/browserless/actions/scrape-url-list/scrape-url-list.mjs b/components/browserless/actions/scrape-url-list/scrape-url-list.mjs index 1881878120071..da5a6cb295c21 100644 --- a/components/browserless/actions/scrape-url-list/scrape-url-list.mjs +++ b/components/browserless/actions/scrape-url-list/scrape-url-list.mjs @@ -4,7 +4,7 @@ export default { key: "browserless-scrape-url-list", name: "Scrape URL List", description: "Scrape content from a list of pages. [See the documentation](https://www.browserless.io/docs/scrape).", - version: "0.0.2", + version: "0.0.3", type: "action", props: { browserless, @@ -28,10 +28,9 @@ export default { } const result = {}; - const promises = []; for (const url of this.urls) { - promises.push(this.browserless.scrape({ + const response = await this.browserless.scrape({ $, data: { url, @@ -39,12 +38,8 @@ export default { selector, })), }, - })); - } - - const responses = await Promise.all(promises); - for (let i = 0; i < promises.length; i++) { - result[this.urls[i]] = responses[i].data[0].results[0].text; + }); + result[url] = response.data[0].results[0].text; } return result; diff --git a/components/browserless/actions/scrape-url/scrape-url.mjs b/components/browserless/actions/scrape-url/scrape-url.mjs index 820dd41baf337..2ef0c23d07d31 100644 --- a/components/browserless/actions/scrape-url/scrape-url.mjs +++ b/components/browserless/actions/scrape-url/scrape-url.mjs @@ -4,7 +4,7 @@ export default { key: "browserless-scrape-url", name: "Scrape URL", description: "Scrape content from a page. [See the documentation](https://www.browserless.io/docs/scrape).", - version: "0.0.2", + version: "0.0.3", type: "action", props: { browserless, diff --git a/components/browserless/actions/take-screenshot/take-screenshot.mjs b/components/browserless/actions/take-screenshot/take-screenshot.mjs index d8d4b08f5d000..1da3ef8df2ebb 100644 --- a/components/browserless/actions/take-screenshot/take-screenshot.mjs +++ b/components/browserless/actions/take-screenshot/take-screenshot.mjs @@ -5,7 +5,7 @@ export default { key: "browserless-take-screenshot", name: "Take a Screenshot", description: "Take a screenshot of a page. [See the documentation](https://www.browserless.io/docs/screenshot)", - version: "0.5.4", + version: "0.5.5", type: "action", props: { browserless, @@ -20,10 +20,10 @@ export default { description: "Download the screenshot to the `/tmp` directory with the specified filename", optional: true, }, - waitFor: { + waitForSelector: { type: "string", - label: "waitFor", - description: "Allows you to wait for a selector to appear in the DOM, to wait for a timeout to happen, or to execute a custom function before screenshotting. See [more details in the API Doc](https://www.browserless.io/docs/screenshot#custom-behavior-with-waitfor)", + label: "Selector", + description: "Allows you to wait for a selector to appear in the DOM. See [more details in the API Doc](https://www.browserless.io/docs/screenshot#custom-behavior-with-waitfor)", optional: true, }, syncDir: { @@ -45,9 +45,10 @@ export default { const screenshot = await this.browserless.takeScreenshot({ data: { url: this.url, - waitFor: !isNaN(this.waitFor) - ? parseInt(this.waitFor) - : this.waitFor, + bestAttempt: true, + waitForSelector: this.waitForSelector + ? `{ "selector": "${this.waitForSelector}" }` + : undefined, }, $, }); diff --git a/components/browserless/browserless.app.mjs b/components/browserless/browserless.app.mjs index 1dabf9b06a7e0..6f2581ed05e13 100644 --- a/components/browserless/browserless.app.mjs +++ b/components/browserless/browserless.app.mjs @@ -1,4 +1,5 @@ import { axios } from "@pipedream/platform"; +import { ConfigurationError } from "@pipedream/platform"; export default { type: "app", @@ -6,7 +7,10 @@ export default { propDefinitions: {}, methods: { _baseUrl() { - return "https://chrome.browserless.io"; + if (!this.$auth.base_url) { + throw new ConfigurationError("Please reconnect your Browserless account because there are recent changes in Browserless API"); + } + return `https://${this.$auth.base_url}`; }, _auth() { return { @@ -50,5 +54,13 @@ export default { ...opts, }); }, + convertHtmlToPdf(opts = {}) { + return this._makeRequest({ + path: "/pdf", + method: "post", + responseType: "arraybuffer", + ...opts, + }); + }, }, }; diff --git a/components/browserless/package.json b/components/browserless/package.json index 9bcbbb4b0ce22..8f21c17bfe564 100644 --- a/components/browserless/package.json +++ b/components/browserless/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/browserless", - "version": "0.1.3", + "version": "0.1.4", "description": "Pipedream Browserless Components", "main": "browserless.app.mjs", "keywords": [ @@ -13,7 +13,7 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.5.1", + "@pipedream/platform": "^3.1.0", "puppeteer-core": "^19.7.5" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 777d319172859..485ae726cc4fd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1945,8 +1945,8 @@ importers: components/browserless: dependencies: '@pipedream/platform': - specifier: ^1.5.1 - version: 1.6.6 + specifier: ^3.1.0 + version: 3.1.0 puppeteer-core: specifier: ^19.7.5 version: 19.11.1(typescript@5.7.2) @@ -10018,8 +10018,7 @@ importers: specifier: ^0.10.0 version: 0.10.0 - components/pdf_munk: - specifiers: {} + components/pdf_munk: {} components/pdffiller: dependencies: @@ -11686,8 +11685,7 @@ importers: specifier: ^0.10.0 version: 0.10.0 - components/rocketskip: - specifiers: {} + components/rocketskip: {} components/rockset: dependencies: @@ -12292,8 +12290,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/serenity_ai_hub: - specifiers: {} + components/serenity_ai_hub: {} components/serpapi: dependencies: @@ -13698,8 +13695,7 @@ importers: specifier: ^1.6.0 version: 1.6.6 - components/templatedocs: - specifiers: {} + components/templatedocs: {} components/tento8: {} @@ -14341,8 +14337,7 @@ importers: components/typebot: {} - components/typeflo: - specifiers: {} + components/typeflo: {} components/typeflowai: dependencies: