Skip to content

Commit 091970e

Browse files
committed
updates
1 parent a5a1152 commit 091970e

File tree

6 files changed

+54
-27
lines changed

6 files changed

+54
-27
lines changed
Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,63 @@
1-
// legacy_hash_id: a_B0ip1E
2-
import { axios } from "@pipedream/platform";
1+
import browserless from "../../browserless.app.mjs";
2+
import fs from "fs";
33

44
export default {
55
key: "browserless-convert-html-to-pdf",
66
name: "Generate PDF from HTML String",
77
description: "See https://docs.browserless.io/docs/pdf.html",
8-
version: "0.4.1",
8+
version: "0.4.2",
99
type: "action",
1010
props: {
11-
browserless: {
12-
type: "app",
13-
app: "browserless",
14-
},
11+
browserless,
1512
html: {
1613
type: "string",
1714
label: "HTML String",
1815
description: "HTML to render as a PDF",
1916
},
17+
downloadPath: {
18+
type: "string",
19+
label: "Download Path",
20+
description: "Download the screenshot to the `/tmp` directory with the specified filename",
21+
optional: true,
22+
},
23+
syncDir: {
24+
type: "dir",
25+
accessMode: "write",
26+
sync: true,
27+
},
28+
},
29+
methods: {
30+
async downloadToTMP(screenshot) {
31+
const path = this.downloadPath.includes("/tmp")
32+
? this.downloadPath
33+
: `/tmp/${this.downloadPath}`;
34+
fs.writeFileSync(path, screenshot);
35+
return path;
36+
},
2037
},
2138
async run({ $ }) {
2239
const { html } = this;
2340

24-
const data = await axios($, {
25-
method: "POST",
26-
url: `https://chrome.browserless.io/pdf?token=${this.browserless.$auth.api_key}`,
27-
headers: {
28-
"Cache-Control": "no-cache",
29-
"Content-Type": "application/json",
30-
},
31-
responseType: "arraybuffer",
41+
const data = await this.browserless.convertHtmlToPdf({
42+
$,
3243
data: {
3344
html,
34-
options: {
35-
displayHeaderFooter: true,
36-
printBackground: false,
37-
format: "Letter",
38-
},
3945
},
4046
});
4147

42-
$.export("pdf", Buffer.from(data, "binary").toString("base64"));
48+
const result = {
49+
pdf: Buffer.from(data, "binary").toString("base64"),
50+
};
51+
52+
if (data && this.downloadPath) {
53+
const filePath = await this.downloadToTMP(data);
54+
result.filePath = filePath;
55+
}
56+
57+
if (data) {
58+
$.export("$summary", "Successfully generated PDF from HTML string.");
59+
}
60+
61+
return result;
4362
},
4463
};

components/browserless/actions/scrape-url-list/scrape-url-list.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "browserless-scrape-url-list",
55
name: "Scrape URL List",
66
description: "Scrape content from a list of pages. [See the documentation](https://www.browserless.io/docs/scrape).",
7-
version: "0.0.2",
7+
version: "0.0.3",
88
type: "action",
99
props: {
1010
browserless,

components/browserless/actions/scrape-url/scrape-url.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "browserless-scrape-url",
55
name: "Scrape URL",
66
description: "Scrape content from a page. [See the documentation](https://www.browserless.io/docs/scrape).",
7-
version: "0.0.2",
7+
version: "0.0.3",
88
type: "action",
99
props: {
1010
browserless,

components/browserless/actions/take-screenshot/take-screenshot.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "browserless-take-screenshot",
66
name: "Take a Screenshot",
77
description: "Take a screenshot of a page. [See the documentation](https://www.browserless.io/docs/screenshot)",
8-
version: "0.5.4",
8+
version: "0.5.5",
99
type: "action",
1010
props: {
1111
browserless,

components/browserless/browserless.app.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
propDefinitions: {},
77
methods: {
88
_baseUrl() {
9-
return "https://chrome.browserless.io";
9+
return `https://${this.$auth.base_url}`;
1010
},
1111
_auth() {
1212
return {
@@ -50,5 +50,13 @@ export default {
5050
...opts,
5151
});
5252
},
53+
convertHtmlToPdf(opts = {}) {
54+
return this._makeRequest({
55+
path: "/pdf",
56+
method: "post",
57+
responseType: "arraybuffer",
58+
...opts,
59+
});
60+
},
5361
},
5462
};

components/browserless/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/browserless",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Pipedream Browserless Components",
55
"main": "browserless.app.mjs",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1",
16+
"@pipedream/platform": "^3.1.0",
1717
"puppeteer-core": "^19.7.5"
1818
}
1919
}

0 commit comments

Comments
 (0)