@d-zero/puppeteer-screenshot 3.1.0 → 3.1.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/dist/get-css.d.ts +6 -0
- package/dist/get-css.js +65 -0
- package/package.json +7 -8
package/dist/get-css.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param page
|
|
4
|
+
*/
|
|
5
|
+
export async function getCSS(page) {
|
|
6
|
+
// DevTools Protocolセッションを開始
|
|
7
|
+
const client = await page.createCDPSession();
|
|
8
|
+
await client.send('DOM.enable');
|
|
9
|
+
await client.send('CSS.enable');
|
|
10
|
+
// 要素のDOM Node IDを取得(まずドキュメントから探索)
|
|
11
|
+
const { root } = await client.send('DOM.getDocument');
|
|
12
|
+
const elements = await client.send('DOM.querySelectorAll', {
|
|
13
|
+
nodeId: root.nodeId,
|
|
14
|
+
selector: '*',
|
|
15
|
+
});
|
|
16
|
+
const result = {};
|
|
17
|
+
for (const nodeId of elements.nodeIds) {
|
|
18
|
+
// ノード情報を取得
|
|
19
|
+
const { node } = await client.send('DOM.describeNode', { nodeId });
|
|
20
|
+
const nodeName = node.localName;
|
|
21
|
+
// CSS.getMatchedStylesForNodeでスタイル情報を取得
|
|
22
|
+
const declarationData = await client.send('CSS.getMatchedStylesForNode', { nodeId });
|
|
23
|
+
const { computedStyle } = await client.send('CSS.getComputedStyleForNode', {
|
|
24
|
+
nodeId,
|
|
25
|
+
});
|
|
26
|
+
// UAスタイル以外のプロパティを抽出
|
|
27
|
+
const { inlineStyle, matchedCSSRules } = declarationData;
|
|
28
|
+
if (computedStyle.find((p) => p.name === 'display')?.value === 'none') {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const explicitProperties = {};
|
|
32
|
+
if (inlineStyle) {
|
|
33
|
+
for (const prop of inlineStyle.cssProperties) {
|
|
34
|
+
if (prop.disabled || !prop.value)
|
|
35
|
+
continue;
|
|
36
|
+
const computedStyleValue = computedStyle.find((p) => p.name === prop.name)?.value;
|
|
37
|
+
if (computedStyleValue === prop.value)
|
|
38
|
+
continue;
|
|
39
|
+
explicitProperties[prop.name + '(inline)'] = prop.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const ruleMatch of matchedCSSRules ?? []) {
|
|
43
|
+
if (ruleMatch.rule.origin === 'regular') {
|
|
44
|
+
// UAスタイルシート以外
|
|
45
|
+
for (const prop of ruleMatch.rule.style.cssProperties) {
|
|
46
|
+
if (!prop.value)
|
|
47
|
+
continue;
|
|
48
|
+
const computedStyleValue = computedStyle.find((p) => p.name === prop.name)?.value;
|
|
49
|
+
if (computedStyleValue === prop.value)
|
|
50
|
+
continue;
|
|
51
|
+
explicitProperties[prop.name + '(regular)'] = prop.value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Sort property name
|
|
56
|
+
const sortedProperties = Object.entries(explicitProperties).toSorted((a, b) => {
|
|
57
|
+
// Remove vendor prefix
|
|
58
|
+
a[0] = a[0].replace(/^-(?:webkit|moz|ms)-/, '');
|
|
59
|
+
b[0] = b[0].replace(/^-(?:webkit|moz|ms)-/, '');
|
|
60
|
+
return a[0].localeCompare(b[0]);
|
|
61
|
+
});
|
|
62
|
+
result[`${nodeName}[${nodeId}]`] = Object.fromEntries(sortedProperties);
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/puppeteer-screenshot",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Screenshot utility for puppeteer",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"private": false,
|
|
8
7
|
"publishConfig": {
|
|
9
8
|
"access": "public"
|
|
10
9
|
},
|
|
@@ -24,15 +23,15 @@
|
|
|
24
23
|
"clean": "tsc --build --clean"
|
|
25
24
|
},
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"@d-zero/puppeteer-general-actions": "1.2.
|
|
28
|
-
"@d-zero/puppeteer-page-scan": "4.0.
|
|
29
|
-
"@d-zero/shared": "0.9.
|
|
26
|
+
"@d-zero/puppeteer-general-actions": "1.2.1",
|
|
27
|
+
"@d-zero/puppeteer-page-scan": "4.0.3",
|
|
28
|
+
"@d-zero/shared": "0.9.1"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
|
-
"puppeteer": "24.
|
|
31
|
+
"puppeteer": "24.12.0"
|
|
33
32
|
},
|
|
34
33
|
"peerDependencies": {
|
|
35
|
-
"puppeteer": "24.
|
|
34
|
+
"puppeteer": "24.12.0"
|
|
36
35
|
},
|
|
37
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "7cc778738d8c811adb69cee528655e12eba52e87"
|
|
38
37
|
}
|