-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] CaptureKit #17530 #17770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
components/capturekit/actions/capture-screenshot/capture-screenshot.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import app from "../../capturekit.app.mjs"; | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
|
|
||
| export default { | ||
| key: "capturekit-capture-screenshot", | ||
| name: "Capture Screenshot", | ||
| description: "Capture a high-quality image of any webpage. [See the documentation](https://docs.capturekit.dev/api-reference/screenshot-api)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| url: { | ||
| propDefinition: [ | ||
| app, | ||
| "url", | ||
| ], | ||
| }, | ||
| format: { | ||
| propDefinition: [ | ||
| app, | ||
| "format", | ||
| ], | ||
| }, | ||
| device: { | ||
| propDefinition: [ | ||
| app, | ||
| "device", | ||
| ], | ||
| }, | ||
| cache: { | ||
| propDefinition: [ | ||
| app, | ||
| "cache", | ||
| ], | ||
| }, | ||
| fullPageScroll: { | ||
| propDefinition: [ | ||
| app, | ||
| "fullPageScroll", | ||
| ], | ||
| }, | ||
| fileName: { | ||
| propDefinition: [ | ||
| app, | ||
| "fileName", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.captureScreenshot({ | ||
| $, | ||
| params: { | ||
| url: this.url, | ||
| format: this.format, | ||
| device: this.device, | ||
| cache: this.cache, | ||
| full_page_scroll: this.fullPageScroll, | ||
| }, | ||
| responseType: "arraybuffer", | ||
| }); | ||
|
|
||
| const fileExtension = this.format || "png"; | ||
| const fileName = `${this.fileName}.${fileExtension}`; | ||
| const filePath = path.join("/tmp", fileName); | ||
|
|
||
| await fs.promises.writeFile(filePath, response); | ||
|
|
||
| $.export("$summary", `Screenshot successfully saved to: ${filePath}`); | ||
|
|
||
| return filePath; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
69 changes: 69 additions & 0 deletions
69
components/capturekit/actions/scrape-content/scrape-content.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import app from "../../capturekit.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "capturekit-scrape-content", | ||
| name: "Scrape Content", | ||
| description: "Extract structured data from any webpage, including metadata, links, and raw HTML. [See the documentation](https://docs.capturekit.dev/api-reference/content-api)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
|
|
||
| url: { | ||
| propDefinition: [ | ||
| app, | ||
| "url", | ||
| ], | ||
| }, | ||
|
|
||
lcaresia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| includeHtml: { | ||
| propDefinition: [ | ||
| app, | ||
| "includeHtml", | ||
| ], | ||
| }, | ||
|
|
||
| useDefuddle: { | ||
| propDefinition: [ | ||
| app, | ||
| "useDefuddle", | ||
| ], | ||
| }, | ||
|
|
||
| selector: { | ||
| propDefinition: [ | ||
| app, | ||
| "selector", | ||
| ], | ||
| }, | ||
|
|
||
| removeSelectors: { | ||
| propDefinition: [ | ||
| app, | ||
| "removeSelectors", | ||
| ], | ||
| }, | ||
|
|
||
| blockUrls: { | ||
| propDefinition: [ | ||
| app, | ||
| "blockUrls", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.scrapeContent({ | ||
| $, | ||
| params: { | ||
| url: this.url, | ||
| include_html: this.includeHtml, | ||
| use_defuddle: this.useDefuddle, | ||
| selector: this.selector, | ||
| remove_selectors: (this.removeSelectors || []).join(","), | ||
| block_urls: (this.blockUrls || []).join(","), | ||
| }, | ||
| }); | ||
| $.export("$summary", "Successfully sent the Scrape Content request"); | ||
| return response; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,134 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "capturekit", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| url: { | ||
| type: "string", | ||
| label: "URL", | ||
| description: "Target webpage to capture", | ||
| }, | ||
| format: { | ||
| type: "string", | ||
| label: "Format", | ||
| description: "The output format of the screenshot", | ||
| optional: true, | ||
| options: [ | ||
| "webp", | ||
| "jpeg", | ||
| "jpg", | ||
| "png", | ||
| "pdf", | ||
| ], | ||
| }, | ||
| device: { | ||
| type: "string", | ||
| label: "Device", | ||
| description: "Device type used for emulation (desktop or mobile)", | ||
| optional: true, | ||
| options: [ | ||
| "iphone_14_pro_max", | ||
| "iphone_14_pro", | ||
| "iphone_13_pro_max", | ||
| "iphone_13_mini", | ||
| "galaxy_s23_ultra", | ||
| "galaxy_s23", | ||
| "galaxy_fold4", | ||
| "pixel_7_pro", | ||
| "pixel_6a", | ||
| "redmi_note_12_pro", | ||
| "redmi_note_11", | ||
| "huawei_p60_pro", | ||
| "huawei_mate_50_pro", | ||
| "iphone_x", | ||
| "iphone_12", | ||
| "pixel_5", | ||
| "galaxy_s8", | ||
| "ipad", | ||
| ], | ||
| }, | ||
| cache: { | ||
| type: "boolean", | ||
| label: "Cache", | ||
| description: "Enable or disable response caching", | ||
| optional: true, | ||
| }, | ||
| fullPageScroll: { | ||
| type: "boolean", | ||
| label: "Full Page Scroll", | ||
| description: "Scroll through the entire page before capturing", | ||
| optional: true, | ||
| }, | ||
| includeHtml: { | ||
| type: "boolean", | ||
| label: "Include HTML", | ||
| description: "Return the raw HTML content in the response", | ||
| optional: true, | ||
| }, | ||
| useDefuddle: { | ||
| type: "boolean", | ||
| label: "Use Defuddle", | ||
| description: "Use Defuddle to clean and extract the main content from web pages", | ||
| optional: true, | ||
| }, | ||
| selector: { | ||
| type: "string", | ||
| label: "Selector", | ||
| description: "Capture a specific element on the page instead of the full viewport", | ||
| optional: true, | ||
| }, | ||
| removeSelectors: { | ||
| type: "string[]", | ||
| label: "Remove Selectors", | ||
| description: "A list of elements to hide before capturing", | ||
| optional: true, | ||
| }, | ||
| blockUrls: { | ||
| type: "string[]", | ||
| label: "Block URLs", | ||
| description: "A ist of URL patterns to block. You can specify URLs, domains, or simple patterns, e.g.: `.example.com/`", | ||
| optional: true, | ||
| }, | ||
| fileName: { | ||
| type: "string", | ||
| label: "File Name", | ||
| description: "Name of the screenshot file that will be saved on /tmp", | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.capturekit.dev"; | ||
| }, | ||
| async _makeRequest(opts = {}) { | ||
| const { | ||
| $ = this, | ||
| path, | ||
| headers, | ||
| ...otherOpts | ||
| } = opts; | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: this._baseUrl() + path, | ||
| headers: { | ||
| "x-access-key": `${this.$auth.access_key}`, | ||
| ...headers, | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| async captureScreenshot(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/capture", | ||
| ...args, | ||
| }); | ||
| }, | ||
|
|
||
| async scrapeContent(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/content", | ||
| ...args, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/capturekit", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream CaptureKit Components", | ||
| "main": "capturekit.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.