screenshotone-api-sdk 1.0.16 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -17
- package/dist/main.js +36 -1
- package/package.json +3 -3
- package/src/main.ts +47 -1
package/README.md
CHANGED
|
@@ -1,34 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jssdk
|
|
2
2
|
|
|
3
|
-
[](https://github.com/screenshotone/jssdk/actions/workflows/build.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/screenshotone-api-sdk)
|
|
4
5
|
|
|
5
6
|
An official [Screenshot API](https://screenshotone.com/) client for JavaScript and TypeScript.
|
|
6
7
|
|
|
7
8
|
It takes minutes to start taking screenshots. Just [sign up](https://screenshotone.com/) to get access and secret keys, import the client, and you are ready to go.
|
|
8
9
|
|
|
10
|
+
The SDK client is synchronized with the latest [screenshot API options](https://screenshotone.com/docs/options/).
|
|
11
|
+
|
|
9
12
|
## Installation
|
|
10
13
|
|
|
11
14
|
```shell
|
|
12
|
-
|
|
15
|
+
npm install screenshotone-api-sdk --save
|
|
13
16
|
```
|
|
14
17
|
|
|
15
18
|
## Usage
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
Generate a screenshot URL without executing the request. Or download the screenshot. It is up to you:
|
|
21
|
+
```javascript
|
|
22
|
+
import * as fs from 'fs';
|
|
23
|
+
import * as screenshotone from 'screenshotone-api-sdk';
|
|
24
|
+
|
|
25
|
+
// create API client
|
|
26
|
+
const client = new screenshotone.Client("<access key>", "<secret key>");
|
|
27
|
+
|
|
28
|
+
// set up options
|
|
29
|
+
const options = screenshotone.TakeOptions
|
|
30
|
+
.url("https://example.com")
|
|
31
|
+
.delay(3)
|
|
32
|
+
.blockAds(true);
|
|
33
|
+
|
|
34
|
+
// generate URL
|
|
35
|
+
const url = client.generateTakeURL(options);
|
|
36
|
+
console.log(url);
|
|
37
|
+
// expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com&delay=3&block_ads=true&access_key=%3Caccess+key%3E&signature=7f3419ece2c53ed2c7923c7d5deef290d662c3643822bf69ec8259ce10b3ea61
|
|
38
|
+
|
|
39
|
+
// or download the screenshot
|
|
40
|
+
const imageBlob = await client.take(options);
|
|
41
|
+
const buffer = Buffer.from(await imageBlob.arrayBuffer());
|
|
42
|
+
fs.writeFileSync("example.png", buffer)
|
|
43
|
+
// the screenshot is store in the example.png file
|
|
30
44
|
```
|
|
31
45
|
|
|
32
46
|
## License
|
|
33
47
|
|
|
34
|
-
`screenshotone/
|
|
48
|
+
`screenshotone/jssdk` is released under [the MIT license](LICENSE).
|
package/dist/main.js
CHANGED
|
@@ -56,7 +56,8 @@ class Client {
|
|
|
56
56
|
if (response.ok) {
|
|
57
57
|
return await response.blob();
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
const data = await response.json();
|
|
60
|
+
throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}: ${data?.message}`);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
exports.Client = Client;
|
|
@@ -75,12 +76,46 @@ class TakeOptions {
|
|
|
75
76
|
static url(url) {
|
|
76
77
|
return new TakeOptions(url);
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Initializes take screenshot options with provided HTML.
|
|
81
|
+
*/
|
|
82
|
+
static html(url) {
|
|
83
|
+
return new TakeOptions(url);
|
|
84
|
+
}
|
|
78
85
|
put(key, ...values) {
|
|
79
86
|
for (const value of values) {
|
|
80
87
|
this.query.append(key, value);
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
90
|
;
|
|
91
|
+
/**
|
|
92
|
+
* Selector is a CSS-like selector of the element to take a screenshot of.
|
|
93
|
+
*/
|
|
94
|
+
selector(selector) {
|
|
95
|
+
this.put("selector", selector);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* It determines the behavior of what to do when selector is not found.
|
|
100
|
+
*/
|
|
101
|
+
errorOnSelectorNotFound(errorOn) {
|
|
102
|
+
this.put("error_on_selector_not_found", errorOn ? "true" : "false");
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Styles specifies custom CSS styles for the page.
|
|
107
|
+
*/
|
|
108
|
+
styles(styles) {
|
|
109
|
+
this.put("styles", styles);
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Scripts specifies custom scripts for the page.
|
|
114
|
+
*/
|
|
115
|
+
scripts(scripts) {
|
|
116
|
+
this.put("scripts", scripts);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
84
119
|
/**
|
|
85
120
|
* Renders the full page.
|
|
86
121
|
*/
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screenshotone-api-sdk",
|
|
3
3
|
"homepage": "https://screenshotone.com",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.19",
|
|
5
5
|
"description": "Use ScreenshotOne.com API to generate screenshots of any website.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/screenshotone/
|
|
8
|
+
"url": "git+https://github.com/screenshotone/jssdk.git"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"screenshot",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"bugs": {
|
|
27
27
|
"email": "support@screenshotone.com",
|
|
28
|
-
"url": "https://github.com/screenshotone/
|
|
28
|
+
"url": "https://github.com/screenshotone/jssdk/issues"
|
|
29
29
|
},
|
|
30
30
|
"main": "dist/main.js",
|
|
31
31
|
"types": "dist/@types/main.d.ts",
|
package/src/main.ts
CHANGED
|
@@ -37,7 +37,9 @@ export class Client {
|
|
|
37
37
|
return await response.blob()
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
|
|
42
|
+
throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}: ${data?.message}`);
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -61,12 +63,56 @@ export class TakeOptions {
|
|
|
61
63
|
return new TakeOptions(url);
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Initializes take screenshot options with provided HTML.
|
|
68
|
+
*/
|
|
69
|
+
static html(url: string): TakeOptions {
|
|
70
|
+
return new TakeOptions(url);
|
|
71
|
+
}
|
|
72
|
+
|
|
64
73
|
private put(key: string, ...values: string[]) {
|
|
65
74
|
for (const value of values) {
|
|
66
75
|
this.query.append(key, value);
|
|
67
76
|
}
|
|
68
77
|
};
|
|
69
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Selector is a CSS-like selector of the element to take a screenshot of.
|
|
81
|
+
*/
|
|
82
|
+
selector(selector: string) {
|
|
83
|
+
this.put("selector", selector);
|
|
84
|
+
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* It determines the behavior of what to do when selector is not found.
|
|
90
|
+
*/
|
|
91
|
+
errorOnSelectorNotFound(errorOn: boolean) {
|
|
92
|
+
this.put("error_on_selector_not_found", errorOn ? "true" : "false");
|
|
93
|
+
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Styles specifies custom CSS styles for the page.
|
|
99
|
+
*/
|
|
100
|
+
styles(styles: string) {
|
|
101
|
+
this.put("styles", styles);
|
|
102
|
+
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Scripts specifies custom scripts for the page.
|
|
108
|
+
*/
|
|
109
|
+
scripts(scripts: string) {
|
|
110
|
+
this.put("scripts", scripts);
|
|
111
|
+
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
70
116
|
/**
|
|
71
117
|
* Renders the full page.
|
|
72
118
|
*/
|