@mario.andreschak/mcp-browser 3.46.0 → 3.46.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 +52 -52
- package/dist/audioTap.js +120 -120
- package/dist/capture.js +40 -40
- package/dist/resources.js +290 -290
- package/dist/viewHtml.js +460 -460
- package/package.json +6 -1
- package/scripts/install-browser.mjs +212 -212
package/README.md
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
# Browser MCP
|
|
2
|
-
|
|
3
|
-
The browser MCP provides interactive Patchright sessions, deterministic PNG capture, and WebM recording.
|
|
4
|
-
|
|
5
|
-
## Evidence artifacts
|
|
6
|
-
|
|
7
|
-
`browser_screenshot` creates an immutable PNG by default under
|
|
8
|
-
`screenshots/browser/<sessionId>/<artifactId>-viewport.png` (or
|
|
9
|
-
`-full-page.png`). An optional `outputPath` is accepted only inside the
|
|
10
|
-
FLUJO data directory or configured screenshot root. Existing destinations,
|
|
11
|
-
root escapes, drive-relative/device/UNC paths, and symlink or junction escapes
|
|
12
|
-
are rejected.
|
|
13
|
-
|
|
14
|
-
Screenshot results include the artifact ID, SHA-256, capture timestamp, CSS
|
|
15
|
-
viewport, DPR, encoded PNG dimensions, and page/session metadata. When the
|
|
16
|
-
target is an active recording, the result also links the PNG to its
|
|
17
|
-
`recordingId` and configured recording geometry. PNGs are lossless evidence;
|
|
18
|
-
callers must still freeze application animation, timestamps, cursors, and
|
|
19
|
-
changing overlays before exact comparisons.
|
|
20
|
-
|
|
21
|
-
## Recording geometry
|
|
22
|
-
|
|
23
|
-
Recording contexts use an explicit CSS viewport and device scale factor 1.
|
|
24
|
-
The configured video surface matches that viewport. Recording sessions have a
|
|
25
|
-
fixed viewport policy: resizing the MCP App or dock scales/letterboxes the live
|
|
26
|
-
stream and never mutates the page used to produce evidence.
|
|
27
|
-
|
|
28
|
-
Start, status, and stop results distinguish:
|
|
29
|
-
|
|
30
|
-
- `requestedViewport`
|
|
31
|
-
- `actualViewport`
|
|
32
|
-
- `deviceScaleFactor`
|
|
33
|
-
- `configuredVideoResolution`
|
|
34
|
-
- `actualEncodedVideoResolution` (after finalization, or `null` with a warning)
|
|
35
|
-
- content bounds, letterbox insets, and `geometryMismatch`
|
|
36
|
-
|
|
37
|
-
WebM remains review/playback evidence; use recording-linked PNG screenshots for
|
|
38
|
-
exact pixel evidence.
|
|
39
|
-
|
|
40
|
-
## Session lifecycle and ownership
|
|
41
|
-
|
|
42
|
-
The backend-provided `_meta.flujo.ownerScope` is authoritative. Calls without
|
|
43
|
-
metadata use the process-local `legacy:anonymous` compatibility scope.
|
|
44
|
-
Session IDs cannot be listed, used, attached, stopped, or closed across owner
|
|
45
|
-
scopes. The live-view gateway additionally requires a private per-session
|
|
46
|
-
capability delivered to the MCP App through result metadata.
|
|
47
|
-
|
|
48
|
-
Capacity is reserved synchronously before browser creation, so concurrent opens
|
|
49
|
-
cannot race above `FLUJO_BROWSER_MAX_SESSIONS`. Dead and expired entries are
|
|
50
|
-
reclaimed before enforcing the cap. `browser_list_sessions` returns
|
|
51
|
-
owner-filtered lifecycle/capacity diagnostics, and `browser_release_owner`
|
|
52
|
-
idempotently finalizes recordings and releases sessions for the caller scope.
|
|
1
|
+
# Browser MCP
|
|
2
|
+
|
|
3
|
+
The browser MCP provides interactive Patchright sessions, deterministic PNG capture, and WebM recording.
|
|
4
|
+
|
|
5
|
+
## Evidence artifacts
|
|
6
|
+
|
|
7
|
+
`browser_screenshot` creates an immutable PNG by default under
|
|
8
|
+
`screenshots/browser/<sessionId>/<artifactId>-viewport.png` (or
|
|
9
|
+
`-full-page.png`). An optional `outputPath` is accepted only inside the
|
|
10
|
+
FLUJO data directory or configured screenshot root. Existing destinations,
|
|
11
|
+
root escapes, drive-relative/device/UNC paths, and symlink or junction escapes
|
|
12
|
+
are rejected.
|
|
13
|
+
|
|
14
|
+
Screenshot results include the artifact ID, SHA-256, capture timestamp, CSS
|
|
15
|
+
viewport, DPR, encoded PNG dimensions, and page/session metadata. When the
|
|
16
|
+
target is an active recording, the result also links the PNG to its
|
|
17
|
+
`recordingId` and configured recording geometry. PNGs are lossless evidence;
|
|
18
|
+
callers must still freeze application animation, timestamps, cursors, and
|
|
19
|
+
changing overlays before exact comparisons.
|
|
20
|
+
|
|
21
|
+
## Recording geometry
|
|
22
|
+
|
|
23
|
+
Recording contexts use an explicit CSS viewport and device scale factor 1.
|
|
24
|
+
The configured video surface matches that viewport. Recording sessions have a
|
|
25
|
+
fixed viewport policy: resizing the MCP App or dock scales/letterboxes the live
|
|
26
|
+
stream and never mutates the page used to produce evidence.
|
|
27
|
+
|
|
28
|
+
Start, status, and stop results distinguish:
|
|
29
|
+
|
|
30
|
+
- `requestedViewport`
|
|
31
|
+
- `actualViewport`
|
|
32
|
+
- `deviceScaleFactor`
|
|
33
|
+
- `configuredVideoResolution`
|
|
34
|
+
- `actualEncodedVideoResolution` (after finalization, or `null` with a warning)
|
|
35
|
+
- content bounds, letterbox insets, and `geometryMismatch`
|
|
36
|
+
|
|
37
|
+
WebM remains review/playback evidence; use recording-linked PNG screenshots for
|
|
38
|
+
exact pixel evidence.
|
|
39
|
+
|
|
40
|
+
## Session lifecycle and ownership
|
|
41
|
+
|
|
42
|
+
The backend-provided `_meta.flujo.ownerScope` is authoritative. Calls without
|
|
43
|
+
metadata use the process-local `legacy:anonymous` compatibility scope.
|
|
44
|
+
Session IDs cannot be listed, used, attached, stopped, or closed across owner
|
|
45
|
+
scopes. The live-view gateway additionally requires a private per-session
|
|
46
|
+
capability delivered to the MCP App through result metadata.
|
|
47
|
+
|
|
48
|
+
Capacity is reserved synchronously before browser creation, so concurrent opens
|
|
49
|
+
cannot race above `FLUJO_BROWSER_MAX_SESSIONS`. Dead and expired entries are
|
|
50
|
+
reclaimed before enforcing the cap. `browser_list_sessions` returns
|
|
51
|
+
owner-filtered lifecycle/capacity diagnostics, and `browser_release_owner`
|
|
52
|
+
idempotently finalizes recordings and releases sessions for the caller scope.
|
package/dist/audioTap.js
CHANGED
|
@@ -22,126 +22,126 @@
|
|
|
22
22
|
*/
|
|
23
23
|
export function audioTapSource(binding, initiallyMuted = false) {
|
|
24
24
|
const muted = initiallyMuted ? 'true' : 'false';
|
|
25
|
-
return `(function(){
|
|
26
|
-
if (window.__flujoAudioTap) { window.__flujoAudioMuted = ${muted}; return; }
|
|
27
|
-
var NativeCtx = window.AudioContext || window.webkitAudioContext;
|
|
28
|
-
if (!NativeCtx) return;
|
|
29
|
-
window.__flujoAudioTap = true;
|
|
30
|
-
window.__flujoAudioMuted = ${muted};
|
|
31
|
-
var CHUNK = 4096;
|
|
32
|
-
var SILENCE = 1 / 32768;
|
|
33
|
-
|
|
34
|
-
function encode(bytes){
|
|
35
|
-
var out = "", step = 0x8000;
|
|
36
|
-
for (var i = 0; i < bytes.length; i += step) {
|
|
37
|
-
out += String.fromCharCode.apply(null, bytes.subarray(i, i + step));
|
|
38
|
-
}
|
|
39
|
-
return btoa(out);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Insert a silent recorder between a context's graph and its real output. */
|
|
43
|
-
function tap(ctx, output){
|
|
44
|
-
var input = ctx.createGain();
|
|
45
|
-
var processor = ctx.createScriptProcessor(CHUNK, 2, 2);
|
|
46
|
-
processor.onaudioprocess = function(event){
|
|
47
|
-
var send = window.${binding};
|
|
48
|
-
if (window.__flujoAudioMuted || typeof send !== "function") return;
|
|
49
|
-
var buffer = event.inputBuffer;
|
|
50
|
-
var frames = buffer.length;
|
|
51
|
-
var left = buffer.getChannelData(0);
|
|
52
|
-
var right = buffer.numberOfChannels > 1 ? buffer.getChannelData(1) : left;
|
|
53
|
-
var pcm = new Int16Array(frames * 2);
|
|
54
|
-
var silent = true;
|
|
55
|
-
for (var i = 0; i < frames; i++) {
|
|
56
|
-
var a = left[i], b = right[i];
|
|
57
|
-
if (a > 1) a = 1; else if (a < -1) a = -1;
|
|
58
|
-
if (b > 1) b = 1; else if (b < -1) b = -1;
|
|
59
|
-
if (silent && (a > SILENCE || a < -SILENCE || b > SILENCE || b < -SILENCE)) silent = false;
|
|
60
|
-
pcm[i * 2] = a * 32767;
|
|
61
|
-
pcm[i * 2 + 1] = b * 32767;
|
|
62
|
-
}
|
|
63
|
-
// Digital silence is the common case on a normal page; never spend
|
|
64
|
-
// bandwidth or CDP round trips on it.
|
|
65
|
-
if (silent) return;
|
|
66
|
-
try {
|
|
67
|
-
send(JSON.stringify({ rate: ctx.sampleRate, pcm: encode(new Uint8Array(pcm.buffer)) }));
|
|
68
|
-
} catch (error) {
|
|
69
|
-
window.__flujoAudioMuted = true;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
input.connect(processor);
|
|
73
|
-
// A ScriptProcessor only runs while it is reachable from the destination.
|
|
74
|
-
// Its own output stays silent because onaudioprocess never writes one.
|
|
75
|
-
processor.connect(output);
|
|
76
|
-
return input;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 1) Pages with their own AudioContext.
|
|
80
|
-
function patch(Ctor){
|
|
81
|
-
if (typeof Ctor !== "function") return Ctor;
|
|
82
|
-
function Patched(){
|
|
83
|
-
var ctx = new (Function.prototype.bind.apply(Ctor, [null].concat([].slice.call(arguments))))();
|
|
84
|
-
try {
|
|
85
|
-
var input = tap(ctx, ctx.destination);
|
|
86
|
-
input.maxChannelCount = ctx.destination.maxChannelCount;
|
|
87
|
-
Object.defineProperty(ctx, "destination", {
|
|
88
|
-
configurable: true,
|
|
89
|
-
get: function(){ return input; }
|
|
90
|
-
});
|
|
91
|
-
} catch (error) { /* an untappable context still plays normally */ }
|
|
92
|
-
return ctx;
|
|
93
|
-
}
|
|
94
|
-
Patched.prototype = Ctor.prototype;
|
|
95
|
-
return Patched;
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
if (window.AudioContext) window.AudioContext = patch(window.AudioContext);
|
|
99
|
-
if (window.webkitAudioContext) window.webkitAudioContext = patch(window.webkitAudioContext);
|
|
100
|
-
} catch (error) { /* frozen globals: media elements below still work */ }
|
|
101
|
-
|
|
102
|
-
// 2) Plain media elements, routed into one shared context on first play.
|
|
103
|
-
var mediaCtx, mediaTap, attached = new WeakSet();
|
|
104
|
-
function attach(element){
|
|
105
|
-
if (attached.has(element)) return;
|
|
106
|
-
try {
|
|
107
|
-
if (!mediaCtx) {
|
|
108
|
-
mediaCtx = new NativeCtx();
|
|
109
|
-
mediaTap = tap(mediaCtx, mediaCtx.destination);
|
|
110
|
-
}
|
|
111
|
-
attached.add(element);
|
|
112
|
-
mediaCtx.createMediaElementSource(element).connect(mediaTap);
|
|
113
|
-
if (mediaCtx.state === "suspended") mediaCtx.resume();
|
|
114
|
-
} catch (error) {
|
|
115
|
-
// Cross-origin media without CORS headers taints the graph; leave the
|
|
116
|
-
// element alone so at least the picture keeps playing.
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
document.addEventListener("play", function(event){
|
|
120
|
-
var target = event.target;
|
|
121
|
-
if (target && (target.tagName === "AUDIO" || target.tagName === "VIDEO")) attach(target);
|
|
122
|
-
}, true);
|
|
123
|
-
|
|
124
|
-
// Installing the tap after a session was opened must still recover media
|
|
125
|
-
// whose play event already fired. The pre-navigation install is the normal
|
|
126
|
-
// path; this scan is the fallback for reused sessions and dynamically added
|
|
127
|
-
// elements that began playing before they entered the document.
|
|
128
|
-
function attachPlaying(root){
|
|
129
|
-
if (!root) return;
|
|
130
|
-
if ((root.tagName === "AUDIO" || root.tagName === "VIDEO") && !root.paused && !root.ended) attach(root);
|
|
131
|
-
if (typeof root.querySelectorAll !== "function") return;
|
|
132
|
-
var media = root.querySelectorAll("audio,video");
|
|
133
|
-
for (var i = 0; i < media.length; i++) {
|
|
134
|
-
if (!media[i].paused && !media[i].ended) attach(media[i]);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
attachPlaying(document);
|
|
138
|
-
if (window.MutationObserver) {
|
|
139
|
-
new MutationObserver(function(records){
|
|
140
|
-
for (var i = 0; i < records.length; i++) {
|
|
141
|
-
for (var j = 0; j < records[i].addedNodes.length; j++) attachPlaying(records[i].addedNodes[j]);
|
|
142
|
-
}
|
|
143
|
-
}).observe(document.documentElement || document, { childList: true, subtree: true });
|
|
144
|
-
}
|
|
25
|
+
return `(function(){
|
|
26
|
+
if (window.__flujoAudioTap) { window.__flujoAudioMuted = ${muted}; return; }
|
|
27
|
+
var NativeCtx = window.AudioContext || window.webkitAudioContext;
|
|
28
|
+
if (!NativeCtx) return;
|
|
29
|
+
window.__flujoAudioTap = true;
|
|
30
|
+
window.__flujoAudioMuted = ${muted};
|
|
31
|
+
var CHUNK = 4096;
|
|
32
|
+
var SILENCE = 1 / 32768;
|
|
33
|
+
|
|
34
|
+
function encode(bytes){
|
|
35
|
+
var out = "", step = 0x8000;
|
|
36
|
+
for (var i = 0; i < bytes.length; i += step) {
|
|
37
|
+
out += String.fromCharCode.apply(null, bytes.subarray(i, i + step));
|
|
38
|
+
}
|
|
39
|
+
return btoa(out);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Insert a silent recorder between a context's graph and its real output. */
|
|
43
|
+
function tap(ctx, output){
|
|
44
|
+
var input = ctx.createGain();
|
|
45
|
+
var processor = ctx.createScriptProcessor(CHUNK, 2, 2);
|
|
46
|
+
processor.onaudioprocess = function(event){
|
|
47
|
+
var send = window.${binding};
|
|
48
|
+
if (window.__flujoAudioMuted || typeof send !== "function") return;
|
|
49
|
+
var buffer = event.inputBuffer;
|
|
50
|
+
var frames = buffer.length;
|
|
51
|
+
var left = buffer.getChannelData(0);
|
|
52
|
+
var right = buffer.numberOfChannels > 1 ? buffer.getChannelData(1) : left;
|
|
53
|
+
var pcm = new Int16Array(frames * 2);
|
|
54
|
+
var silent = true;
|
|
55
|
+
for (var i = 0; i < frames; i++) {
|
|
56
|
+
var a = left[i], b = right[i];
|
|
57
|
+
if (a > 1) a = 1; else if (a < -1) a = -1;
|
|
58
|
+
if (b > 1) b = 1; else if (b < -1) b = -1;
|
|
59
|
+
if (silent && (a > SILENCE || a < -SILENCE || b > SILENCE || b < -SILENCE)) silent = false;
|
|
60
|
+
pcm[i * 2] = a * 32767;
|
|
61
|
+
pcm[i * 2 + 1] = b * 32767;
|
|
62
|
+
}
|
|
63
|
+
// Digital silence is the common case on a normal page; never spend
|
|
64
|
+
// bandwidth or CDP round trips on it.
|
|
65
|
+
if (silent) return;
|
|
66
|
+
try {
|
|
67
|
+
send(JSON.stringify({ rate: ctx.sampleRate, pcm: encode(new Uint8Array(pcm.buffer)) }));
|
|
68
|
+
} catch (error) {
|
|
69
|
+
window.__flujoAudioMuted = true;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
input.connect(processor);
|
|
73
|
+
// A ScriptProcessor only runs while it is reachable from the destination.
|
|
74
|
+
// Its own output stays silent because onaudioprocess never writes one.
|
|
75
|
+
processor.connect(output);
|
|
76
|
+
return input;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 1) Pages with their own AudioContext.
|
|
80
|
+
function patch(Ctor){
|
|
81
|
+
if (typeof Ctor !== "function") return Ctor;
|
|
82
|
+
function Patched(){
|
|
83
|
+
var ctx = new (Function.prototype.bind.apply(Ctor, [null].concat([].slice.call(arguments))))();
|
|
84
|
+
try {
|
|
85
|
+
var input = tap(ctx, ctx.destination);
|
|
86
|
+
input.maxChannelCount = ctx.destination.maxChannelCount;
|
|
87
|
+
Object.defineProperty(ctx, "destination", {
|
|
88
|
+
configurable: true,
|
|
89
|
+
get: function(){ return input; }
|
|
90
|
+
});
|
|
91
|
+
} catch (error) { /* an untappable context still plays normally */ }
|
|
92
|
+
return ctx;
|
|
93
|
+
}
|
|
94
|
+
Patched.prototype = Ctor.prototype;
|
|
95
|
+
return Patched;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
if (window.AudioContext) window.AudioContext = patch(window.AudioContext);
|
|
99
|
+
if (window.webkitAudioContext) window.webkitAudioContext = patch(window.webkitAudioContext);
|
|
100
|
+
} catch (error) { /* frozen globals: media elements below still work */ }
|
|
101
|
+
|
|
102
|
+
// 2) Plain media elements, routed into one shared context on first play.
|
|
103
|
+
var mediaCtx, mediaTap, attached = new WeakSet();
|
|
104
|
+
function attach(element){
|
|
105
|
+
if (attached.has(element)) return;
|
|
106
|
+
try {
|
|
107
|
+
if (!mediaCtx) {
|
|
108
|
+
mediaCtx = new NativeCtx();
|
|
109
|
+
mediaTap = tap(mediaCtx, mediaCtx.destination);
|
|
110
|
+
}
|
|
111
|
+
attached.add(element);
|
|
112
|
+
mediaCtx.createMediaElementSource(element).connect(mediaTap);
|
|
113
|
+
if (mediaCtx.state === "suspended") mediaCtx.resume();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// Cross-origin media without CORS headers taints the graph; leave the
|
|
116
|
+
// element alone so at least the picture keeps playing.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
document.addEventListener("play", function(event){
|
|
120
|
+
var target = event.target;
|
|
121
|
+
if (target && (target.tagName === "AUDIO" || target.tagName === "VIDEO")) attach(target);
|
|
122
|
+
}, true);
|
|
123
|
+
|
|
124
|
+
// Installing the tap after a session was opened must still recover media
|
|
125
|
+
// whose play event already fired. The pre-navigation install is the normal
|
|
126
|
+
// path; this scan is the fallback for reused sessions and dynamically added
|
|
127
|
+
// elements that began playing before they entered the document.
|
|
128
|
+
function attachPlaying(root){
|
|
129
|
+
if (!root) return;
|
|
130
|
+
if ((root.tagName === "AUDIO" || root.tagName === "VIDEO") && !root.paused && !root.ended) attach(root);
|
|
131
|
+
if (typeof root.querySelectorAll !== "function") return;
|
|
132
|
+
var media = root.querySelectorAll("audio,video");
|
|
133
|
+
for (var i = 0; i < media.length; i++) {
|
|
134
|
+
if (!media[i].paused && !media[i].ended) attach(media[i]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
attachPlaying(document);
|
|
138
|
+
if (window.MutationObserver) {
|
|
139
|
+
new MutationObserver(function(records){
|
|
140
|
+
for (var i = 0; i < records.length; i++) {
|
|
141
|
+
for (var j = 0; j < records[i].addedNodes.length; j++) attachPlaying(records[i].addedNodes[j]);
|
|
142
|
+
}
|
|
143
|
+
}).observe(document.documentElement || document, { childList: true, subtree: true });
|
|
144
|
+
}
|
|
145
145
|
})();`;
|
|
146
146
|
}
|
|
147
147
|
//# sourceMappingURL=audioTap.js.map
|
package/dist/capture.js
CHANGED
|
@@ -280,46 +280,46 @@ export async function captureRegionPng(page, source, region, timeoutMs) {
|
|
|
280
280
|
* passed as *data* arguments only — never string-concatenated into code — so
|
|
281
281
|
* this cannot become a general JS-evaluate primitive (D4).
|
|
282
282
|
*/
|
|
283
|
-
const ELEMENT_METRICS_SCRIPT = `(function(selectors){
|
|
284
|
-
function overflowClass(value, scrollSize, clientSize){
|
|
285
|
-
if (value === "visible") return "visible";
|
|
286
|
-
if (scrollSize > clientSize) return value === "scroll" ? "scroll" : "clipped";
|
|
287
|
-
return value;
|
|
288
|
-
}
|
|
289
|
-
return selectors.map(function(selector){
|
|
290
|
-
var el = document.querySelector(selector);
|
|
291
|
-
if (!el) return { selector: selector, found: false };
|
|
292
|
-
var rect = el.getBoundingClientRect();
|
|
293
|
-
var style = window.getComputedStyle(el);
|
|
294
|
-
var viewportW = window.innerWidth, viewportH = window.innerHeight;
|
|
295
|
-
var isVisible = style.visibility !== "hidden" && style.display !== "none" && rect.width > 0 && rect.height > 0;
|
|
296
|
-
var isInViewport = rect.top < viewportH && rect.bottom > 0 && rect.left < viewportW && rect.right > 0;
|
|
297
|
-
return {
|
|
298
|
-
selector: selector,
|
|
299
|
-
found: true,
|
|
300
|
-
boundingBox: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
301
|
-
clientRect: { top: rect.top, left: rect.left, right: rect.right, bottom: rect.bottom, width: rect.width, height: rect.height },
|
|
302
|
-
scrollWidth: el.scrollWidth,
|
|
303
|
-
scrollHeight: el.scrollHeight,
|
|
304
|
-
isVisible: isVisible,
|
|
305
|
-
isInViewport: isInViewport,
|
|
306
|
-
overflowX: overflowClass(style.overflowX, el.scrollWidth, el.clientWidth),
|
|
307
|
-
overflowY: overflowClass(style.overflowY, el.scrollHeight, el.clientHeight),
|
|
308
|
-
textOverflow: el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight,
|
|
309
|
-
actionSafe: isVisible && isInViewport,
|
|
310
|
-
computed: {
|
|
311
|
-
fontSize: style.fontSize,
|
|
312
|
-
lineHeight: style.lineHeight,
|
|
313
|
-
color: style.color,
|
|
314
|
-
backgroundColor: style.backgroundColor,
|
|
315
|
-
opacity: style.opacity,
|
|
316
|
-
zIndex: style.zIndex,
|
|
317
|
-
transform: style.transform,
|
|
318
|
-
display: style.display,
|
|
319
|
-
position: style.position,
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
});
|
|
283
|
+
const ELEMENT_METRICS_SCRIPT = `(function(selectors){
|
|
284
|
+
function overflowClass(value, scrollSize, clientSize){
|
|
285
|
+
if (value === "visible") return "visible";
|
|
286
|
+
if (scrollSize > clientSize) return value === "scroll" ? "scroll" : "clipped";
|
|
287
|
+
return value;
|
|
288
|
+
}
|
|
289
|
+
return selectors.map(function(selector){
|
|
290
|
+
var el = document.querySelector(selector);
|
|
291
|
+
if (!el) return { selector: selector, found: false };
|
|
292
|
+
var rect = el.getBoundingClientRect();
|
|
293
|
+
var style = window.getComputedStyle(el);
|
|
294
|
+
var viewportW = window.innerWidth, viewportH = window.innerHeight;
|
|
295
|
+
var isVisible = style.visibility !== "hidden" && style.display !== "none" && rect.width > 0 && rect.height > 0;
|
|
296
|
+
var isInViewport = rect.top < viewportH && rect.bottom > 0 && rect.left < viewportW && rect.right > 0;
|
|
297
|
+
return {
|
|
298
|
+
selector: selector,
|
|
299
|
+
found: true,
|
|
300
|
+
boundingBox: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
301
|
+
clientRect: { top: rect.top, left: rect.left, right: rect.right, bottom: rect.bottom, width: rect.width, height: rect.height },
|
|
302
|
+
scrollWidth: el.scrollWidth,
|
|
303
|
+
scrollHeight: el.scrollHeight,
|
|
304
|
+
isVisible: isVisible,
|
|
305
|
+
isInViewport: isInViewport,
|
|
306
|
+
overflowX: overflowClass(style.overflowX, el.scrollWidth, el.clientWidth),
|
|
307
|
+
overflowY: overflowClass(style.overflowY, el.scrollHeight, el.clientHeight),
|
|
308
|
+
textOverflow: el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight,
|
|
309
|
+
actionSafe: isVisible && isInViewport,
|
|
310
|
+
computed: {
|
|
311
|
+
fontSize: style.fontSize,
|
|
312
|
+
lineHeight: style.lineHeight,
|
|
313
|
+
color: style.color,
|
|
314
|
+
backgroundColor: style.backgroundColor,
|
|
315
|
+
opacity: style.opacity,
|
|
316
|
+
zIndex: style.zIndex,
|
|
317
|
+
transform: style.transform,
|
|
318
|
+
display: style.display,
|
|
319
|
+
position: style.position,
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
323
|
})`;
|
|
324
324
|
export async function evaluateElementMetrics(page, selectors) {
|
|
325
325
|
return page.evaluate(ELEMENT_METRICS_SCRIPT, selectors);
|