Skip to content

Commit 6d19333

Browse files
authored
Screenshotbase - New Action (#18752)
* new component * pnpm-lock.yaml * update * updates
1 parent 72793d0 commit 6d19333

File tree

4 files changed

+182
-11
lines changed

4 files changed

+182
-11
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import screenshotbase from "../../screenshotbase.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import fs from "fs";
4+
5+
export default {
6+
key: "screenshotbase-take-screenshot",
7+
name: "Take a Screenshot",
8+
description: "Take a screenshot with ScreenshotBase. [See the documentation](https://screenshotbase.com/docs/take)",
9+
version: "0.0.1",
10+
type: "action",
11+
annotations: {
12+
destructiveHint: false,
13+
openWorldHint: true,
14+
readOnlyHint: false,
15+
},
16+
props: {
17+
screenshotbase,
18+
url: {
19+
propDefinition: [
20+
screenshotbase,
21+
"url",
22+
],
23+
},
24+
format: {
25+
propDefinition: [
26+
screenshotbase,
27+
"format",
28+
],
29+
},
30+
filename: {
31+
propDefinition: [
32+
screenshotbase,
33+
"filename",
34+
],
35+
},
36+
quality: {
37+
propDefinition: [
38+
screenshotbase,
39+
"quality",
40+
],
41+
},
42+
fullPage: {
43+
propDefinition: [
44+
screenshotbase,
45+
"fullPage",
46+
],
47+
},
48+
viewportWidth: {
49+
propDefinition: [
50+
screenshotbase,
51+
"viewportWidth",
52+
],
53+
},
54+
viewportHeight: {
55+
propDefinition: [
56+
screenshotbase,
57+
"viewportHeight",
58+
],
59+
},
60+
syncDir: {
61+
type: "dir",
62+
accessMode: "write",
63+
sync: true,
64+
},
65+
},
66+
async run({ $ }) {
67+
if (this.quality && this.format !== "jpg" && this.format !== "jpeg") {
68+
throw new ConfigurationError("**Quality** is only supported when the format is `jpg` or `jpeg`");
69+
}
70+
71+
try {
72+
const response = await this.screenshotbase.takeScreenshot({
73+
$,
74+
params: {
75+
url: this.url,
76+
format: this.format,
77+
quality: this.quality,
78+
full_page: this.fullPage
79+
? 1
80+
: undefined,
81+
viewport_width: this.viewportWidth,
82+
viewport_height: this.viewportHeight,
83+
},
84+
});
85+
86+
const downloadedFilepath = `/tmp/${this.filename}`;
87+
fs.writeFileSync(downloadedFilepath, response);
88+
89+
const filedata = [
90+
this.filename,
91+
downloadedFilepath,
92+
];
93+
94+
$.export("$summary", `Successfully took the screenshot from ${this.url}`);
95+
return filedata;
96+
} catch (error) {
97+
throw new Error(`Unable to take screenshot from ${this.url}: ${error.name}`);
98+
}
99+
},
100+
};

components/screenshotbase/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/screenshotbase",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream screenshotbase Components",
55
"main": "screenshotbase.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,75 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "screenshotbase",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
url: {
8+
label: "URL",
9+
type: "string",
10+
description: "Website to render",
11+
},
12+
filename: {
13+
type: "string",
14+
label: "Target Filename",
15+
description: "The filename (including extension) that will be used to save the file in /tmp",
16+
},
17+
format: {
18+
type: "string",
19+
label: "Format",
20+
description: "The format of the image returned",
21+
options: [
22+
"jpg",
23+
"png",
24+
"webp",
25+
],
26+
},
27+
quality: {
28+
type: "integer",
29+
label: "Quality",
30+
description: "The quality of the image returned. Only supported when the format is `jpg` or `jpeg`",
31+
optional: true,
32+
},
33+
fullPage: {
34+
type: "boolean",
35+
label: "Full Page",
36+
description: "Whether to take a screenshot of the full page",
37+
optional: true,
38+
},
39+
viewportWidth: {
40+
type: "integer",
41+
label: "Viewport Width",
42+
description: "The width of the browser viewport in pixels. The browser's viewport is the window area where you can see the website. Default value is 1280.",
43+
optional: true,
44+
},
45+
viewportHeight: {
46+
type: "integer",
47+
label: "Viewport Height",
48+
description: "The height of the browser viewport in pixels. The browser's viewport is the window area where you can see the website. Default value is 800.",
49+
optional: true,
50+
},
51+
},
552
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
53+
_baseUrl() {
54+
return "https://api.screenshotbase.com/v1";
55+
},
56+
_makeRequest({
57+
$ = this, path, ...opts
58+
}) {
59+
return axios($, {
60+
url: `${this._baseUrl()}${path}`,
61+
headers: {
62+
"apikey": `${this.$auth.api_key}`,
63+
},
64+
...opts,
65+
});
66+
},
67+
takeScreenshot(opts = {}) {
68+
return this._makeRequest({
69+
path: "/take",
70+
responseType: "arraybuffer",
71+
...opts,
72+
});
973
},
1074
},
1175
};

pnpm-lock.yaml

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)