@d-zero/puppeteer-screenshot 3.3.0 → 3.3.2
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 +78 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ yarn install @d-zero/puppeteer-screenshot
|
|
|
10
10
|
|
|
11
11
|
## 使い方
|
|
12
12
|
|
|
13
|
+
### 基本的な使い方
|
|
14
|
+
|
|
13
15
|
```ts
|
|
14
16
|
import { screenshot } from '@d-zero/puppeteer-screenshot';
|
|
15
17
|
|
|
@@ -23,9 +25,84 @@ const result = await screenshot(page, 'https://example.com', {
|
|
|
23
25
|
desktop: { width: 1400 },
|
|
24
26
|
mobile: { width: 375, resolution: 2 },
|
|
25
27
|
},
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### リスナーを使ったロギング
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { screenshot, screenshotListener } from '@d-zero/puppeteer-screenshot';
|
|
35
|
+
|
|
36
|
+
const result = await screenshot(page, 'https://example.com', {
|
|
37
|
+
listener: screenshotListener, // 標準のログ出力リスナー
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// またはカスタムリスナー
|
|
41
|
+
const result = await screenshot(page, 'https://example.com', {
|
|
26
42
|
listener: (phase, data) => {
|
|
27
43
|
console.log(phase, data);
|
|
28
44
|
},
|
|
29
|
-
openDisclosures: true, // オプション: disclosure要素を展開(<details>とbutton[aria-expanded="false"]、最大1000回まで繰り返す)
|
|
30
45
|
});
|
|
31
46
|
```
|
|
47
|
+
|
|
48
|
+
## オプション
|
|
49
|
+
|
|
50
|
+
| オプション | 型 | 説明 |
|
|
51
|
+
| ----------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `id` | `string` | スクリーンショットのカスタム識別子。省略時はURLからファイル名が生成されます |
|
|
53
|
+
| `path` | `string` | スクリーンショットの保存先パス。指定するとファイルに保存されます(例: `path/to/save.png`はサイズ別に`save@desktop.png`、`save@mobile.png`などに保存) |
|
|
54
|
+
| `sizes` | `Sizes` | スクリーンショットを撮るサイズと解像度の設定。省略時はデフォルトサイズ(desktop、tablet、mobile)が使用されます |
|
|
55
|
+
| `hooks` | `PageHook[]` | ページスキャン時に実行するフック関数の配列 |
|
|
56
|
+
| `listener` | `Listener<ScreenshotPhase>` | スクリーンショット処理の各フェーズをリスンする関数。`screenshotListener`を使うと標準のログ出力が得られます |
|
|
57
|
+
| `domOnly` | `boolean` | `true`の場合、スクリーンショットの撮影をスキップしてDOMのみを取得します(デフォルト: `false`) |
|
|
58
|
+
| `selector` | `string` | 特定の要素のみをスクリーンショット撮影するためのCSSセレクター |
|
|
59
|
+
| `ignore` | `string` | スクリーンショットから除外する(非表示にする)要素のCSSセレクター |
|
|
60
|
+
| `timeout` | `number` | カスタムタイムアウト値(ミリ秒) |
|
|
61
|
+
| `openDisclosures` | `boolean` | `true`の場合、disclosure要素(`<details>`と`button[aria-expanded="false"]`)を展開します(最大1000回まで繰り返す) |
|
|
62
|
+
|
|
63
|
+
## エクスポート
|
|
64
|
+
|
|
65
|
+
### `screenshot(page, url, options?)`
|
|
66
|
+
|
|
67
|
+
指定されたURLのページのスクリーンショットを撮影します。
|
|
68
|
+
|
|
69
|
+
### `screenshotListener`
|
|
70
|
+
|
|
71
|
+
スクリーンショット処理のログを標準出力に出力するための事前設定されたリスナー関数です。
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { screenshot, screenshotListener } from '@d-zero/puppeteer-screenshot';
|
|
75
|
+
|
|
76
|
+
const result = await screenshot(page, 'https://example.com', {
|
|
77
|
+
listener: screenshotListener,
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 型のエクスポート
|
|
82
|
+
|
|
83
|
+
### `Screenshot`
|
|
84
|
+
|
|
85
|
+
`screenshot`関数の戻り値の型です。サイズごとのスクリーンショット結果を含むオブジェクトです。
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
type Screenshot = {
|
|
89
|
+
id: string; // スクリーンショットの識別子
|
|
90
|
+
filePath: string | null; // 保存先ファイルパス(pathオプション指定時)
|
|
91
|
+
url: string; // 対象URL
|
|
92
|
+
title: string; // ページタイトル
|
|
93
|
+
binary: Uint8Array | null; // スクリーンショットのバイナリデータ
|
|
94
|
+
dom: string; // ページのDOM文字列
|
|
95
|
+
text: {
|
|
96
|
+
textContent: string; // ページのテキストコンテンツ
|
|
97
|
+
altTextList: readonly string[]; // 画像のalt属性リスト
|
|
98
|
+
};
|
|
99
|
+
} & Size; // サイズ情報(width, height, resolution)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `ScreenshotPhase`
|
|
103
|
+
|
|
104
|
+
リスナー関数に渡されるフェーズの型です。
|
|
105
|
+
|
|
106
|
+
### `PageHook`
|
|
107
|
+
|
|
108
|
+
`@d-zero/puppeteer-page-scan`から再エクスポートされるページフック関数の型です。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/puppeteer-screenshot",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "Screenshot utility for puppeteer",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"clean": "tsc --build --clean"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@d-zero/puppeteer-general-actions": "1.2.
|
|
27
|
-
"@d-zero/puppeteer-page-scan": "4.4.
|
|
28
|
-
"@d-zero/shared": "0.
|
|
26
|
+
"@d-zero/puppeteer-general-actions": "1.2.2",
|
|
27
|
+
"@d-zero/puppeteer-page-scan": "4.4.2",
|
|
28
|
+
"@d-zero/shared": "0.18.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"puppeteer": "24.
|
|
31
|
+
"puppeteer": "24.37.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"puppeteer": "24.
|
|
34
|
+
"puppeteer": "24.37.2"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "a6d7b36c485bbc0782375c6e1ad0d0606f423e97"
|
|
37
37
|
}
|