Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,23 +28,18 @@ 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,
elements: this.selectors?.map((selector) => ({
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;
Expand Down
2 changes: 1 addition & 1 deletion components/browserless/actions/scrape-url/scrape-url.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: {
Expand All @@ -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,
},
$,
});
Expand Down
14 changes: 13 additions & 1 deletion components/browserless/browserless.app.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { axios } from "@pipedream/platform";
import { ConfigurationError } from "@pipedream/platform";

export default {
type: "app",
app: "browserless",
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 {
Expand Down Expand Up @@ -50,5 +54,13 @@ export default {
...opts,
});
},
convertHtmlToPdf(opts = {}) {
return this._makeRequest({
path: "/pdf",
method: "post",
responseType: "arraybuffer",
...opts,
});
},
},
};
4 changes: 2 additions & 2 deletions components/browserless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/browserless",
"version": "0.1.3",
"version": "0.1.4",
"description": "Pipedream Browserless Components",
"main": "browserless.app.mjs",
"keywords": [
Expand All @@ -13,7 +13,7 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.5.1",
"@pipedream/platform": "^3.1.0",
"puppeteer-core": "^19.7.5"
}
}
19 changes: 7 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading