Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 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 Down
10 changes: 9 additions & 1 deletion components/browserless/browserless.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
propDefinitions: {},
methods: {
_baseUrl() {
return "https://chrome.browserless.io";
return `https://${this.$auth.base_url}`;
},
_auth() {
return {
Expand Down Expand Up @@ -50,5 +50,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