Skip to content

Commit cdbceec

Browse files
Merging pull request #17770
* Added actions * Update components/capturekit/actions/capture-screenshot/capture-screenshot.mjs Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com> * Added actions --------- Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com>
1 parent 3275491 commit cdbceec

File tree

5 files changed

+278
-7
lines changed

5 files changed

+278
-7
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import app from "../../capturekit.app.mjs";
2+
import fs from "fs";
3+
import path from "path";
4+
5+
export default {
6+
key: "capturekit-capture-screenshot",
7+
name: "Capture Screenshot",
8+
description: "Capture a high-quality image of any webpage. [See the documentation](https://docs.capturekit.dev/api-reference/screenshot-api)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
url: {
14+
propDefinition: [
15+
app,
16+
"url",
17+
],
18+
},
19+
format: {
20+
propDefinition: [
21+
app,
22+
"format",
23+
],
24+
},
25+
device: {
26+
propDefinition: [
27+
app,
28+
"device",
29+
],
30+
},
31+
cache: {
32+
propDefinition: [
33+
app,
34+
"cache",
35+
],
36+
},
37+
fullPageScroll: {
38+
propDefinition: [
39+
app,
40+
"fullPageScroll",
41+
],
42+
},
43+
fileName: {
44+
propDefinition: [
45+
app,
46+
"fileName",
47+
],
48+
},
49+
syncDir: {
50+
type: "dir",
51+
accessMode: "write",
52+
sync: true,
53+
},
54+
},
55+
async run({ $ }) {
56+
const response = await this.app.captureScreenshot({
57+
$,
58+
params: {
59+
url: this.url,
60+
format: this.format,
61+
device: this.device,
62+
cache: this.cache,
63+
full_page_scroll: this.fullPageScroll,
64+
},
65+
responseType: "arraybuffer",
66+
});
67+
68+
const fileExtension = this.format || "png";
69+
const fileName = `${this.fileName}.${fileExtension}`;
70+
const filePath = path.join("/tmp", fileName);
71+
72+
await fs.promises.writeFile(filePath, response);
73+
74+
$.export("$summary", `Screenshot successfully saved to: ${filePath}`);
75+
76+
return filePath;
77+
},
78+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../capturekit.app.mjs";
2+
3+
export default {
4+
key: "capturekit-scrape-content",
5+
name: "Scrape Content",
6+
description: "Extract structured data from any webpage, including metadata, links, and raw HTML. [See the documentation](https://docs.capturekit.dev/api-reference/content-api)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
url: {
12+
propDefinition: [
13+
app,
14+
"url",
15+
],
16+
},
17+
includeHtml: {
18+
propDefinition: [
19+
app,
20+
"includeHtml",
21+
],
22+
},
23+
useDefuddle: {
24+
propDefinition: [
25+
app,
26+
"useDefuddle",
27+
],
28+
},
29+
selector: {
30+
propDefinition: [
31+
app,
32+
"selector",
33+
],
34+
},
35+
removeSelectors: {
36+
propDefinition: [
37+
app,
38+
"removeSelectors",
39+
],
40+
},
41+
blockUrls: {
42+
propDefinition: [
43+
app,
44+
"blockUrls",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
const response = await this.app.scrapeContent({
50+
$,
51+
params: {
52+
url: this.url,
53+
include_html: this.includeHtml,
54+
use_defuddle: this.useDefuddle,
55+
selector: this.selector,
56+
remove_selectors: (this.removeSelectors || []).join(","),
57+
block_urls: (this.blockUrls || []).join(","),
58+
},
59+
});
60+
$.export("$summary", "Successfully sent the Scrape Content request");
61+
return response;
62+
},
63+
};
Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,134 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "capturekit",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
url: {
8+
type: "string",
9+
label: "URL",
10+
description: "Target webpage to capture",
11+
},
12+
format: {
13+
type: "string",
14+
label: "Format",
15+
description: "The output format of the screenshot",
16+
optional: true,
17+
options: [
18+
"webp",
19+
"jpeg",
20+
"jpg",
21+
"png",
22+
"pdf",
23+
],
24+
},
25+
device: {
26+
type: "string",
27+
label: "Device",
28+
description: "Device type used for emulation (desktop or mobile)",
29+
optional: true,
30+
options: [
31+
"iphone_14_pro_max",
32+
"iphone_14_pro",
33+
"iphone_13_pro_max",
34+
"iphone_13_mini",
35+
"galaxy_s23_ultra",
36+
"galaxy_s23",
37+
"galaxy_fold4",
38+
"pixel_7_pro",
39+
"pixel_6a",
40+
"redmi_note_12_pro",
41+
"redmi_note_11",
42+
"huawei_p60_pro",
43+
"huawei_mate_50_pro",
44+
"iphone_x",
45+
"iphone_12",
46+
"pixel_5",
47+
"galaxy_s8",
48+
"ipad",
49+
],
50+
},
51+
cache: {
52+
type: "boolean",
53+
label: "Cache",
54+
description: "Enable or disable response caching",
55+
optional: true,
56+
},
57+
fullPageScroll: {
58+
type: "boolean",
59+
label: "Full Page Scroll",
60+
description: "Scroll through the entire page before capturing",
61+
optional: true,
62+
},
63+
includeHtml: {
64+
type: "boolean",
65+
label: "Include HTML",
66+
description: "Return the raw HTML content in the response",
67+
optional: true,
68+
},
69+
useDefuddle: {
70+
type: "boolean",
71+
label: "Use Defuddle",
72+
description: "Use Defuddle to clean and extract the main content from web pages",
73+
optional: true,
74+
},
75+
selector: {
76+
type: "string",
77+
label: "Selector",
78+
description: "Capture a specific element on the page instead of the full viewport",
79+
optional: true,
80+
},
81+
removeSelectors: {
82+
type: "string[]",
83+
label: "Remove Selectors",
84+
description: "A list of elements to hide before capturing",
85+
optional: true,
86+
},
87+
blockUrls: {
88+
type: "string[]",
89+
label: "Block URLs",
90+
description: "A ist of URL patterns to block. You can specify URLs, domains, or simple patterns, e.g.: `.example.com/`",
91+
optional: true,
92+
},
93+
fileName: {
94+
type: "string",
95+
label: "File Name",
96+
description: "Name of the screenshot file that will be saved on /tmp",
97+
},
98+
},
599
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
100+
_baseUrl() {
101+
return "https://api.capturekit.dev";
102+
},
103+
async _makeRequest(opts = {}) {
104+
const {
105+
$ = this,
106+
path,
107+
headers,
108+
...otherOpts
109+
} = opts;
110+
return axios($, {
111+
...otherOpts,
112+
url: this._baseUrl() + path,
113+
headers: {
114+
"x-access-key": `${this.$auth.access_key}`,
115+
...headers,
116+
},
117+
});
118+
},
119+
120+
async captureScreenshot(args = {}) {
121+
return this._makeRequest({
122+
path: "/capture",
123+
...args,
124+
});
125+
},
126+
127+
async scrapeContent(args = {}) {
128+
return this._makeRequest({
129+
path: "/content",
130+
...args,
131+
});
9132
},
10133
},
11134
};

components/capturekit/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/capturekit",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream CaptureKit Components",
55
"main": "capturekit.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)