Skip to content

Commit f2225da

Browse files
sebavanCopilot
andcommitted
fix: extension capture works regardless of captureOffScreen toggle
The capture handler used captureOffScreen flag to decide which array to look up the canvas index from. Workers are always in __SPECTOR_Canvases but captureOffScreen defaults to false, so the handler looked in DOM canvases instead — missing the Worker proxy entirely. Fixed by always checking __SPECTOR_Canvases first (where Worker proxies live), falling back to DOM query only for legacy canvases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f8113e3 commit f2225da

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

extensions/contentScript.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,22 @@ if (sessionStorage.getItem(spectorLoadedKey)) {
259259
document.addEventListener("SpectorRequestCaptureEvent", function(e) {
260260
var canvasIndex = document.getElementById(spectorCommunicationElementId).value;
261261

262+
// Always look up from __SPECTOR_Canvases first (includes Workers and OffscreenCanvases).
263+
// Fall back to DOM query for legacy compatibility.
262264
var canvas = null;
263-
if (captureOffScreen) {
265+
if (window.__SPECTOR_Canvases && window.__SPECTOR_Canvases[canvasIndex]) {
264266
canvas = window.__SPECTOR_Canvases[canvasIndex];
265-
} else {
267+
} else if (!captureOffScreen) {
266268
canvas = document.body.querySelectorAll("canvas")[canvasIndex];
267269
}
268270
var quickCapture = (document.getElementById(spectorCommunicationQuickCaptureElementId).value === "true");
269271
var fullCapture = (document.getElementById(spectorCommunicationFullCaptureElementId).value === "true");
270272
var commandCount = 0 + document.getElementById(spectorCommunicationCommandCountElementId).value;
271273

272274
// Route Worker proxy entries — send trigger directly to Worker
273-
// to bypass the main-thread spy chain (which only captures partial frames)
274275
if (canvas && canvas.__spector_worker) {
275276
var worker = canvas.__spector_worker;
276277

277-
// Listen for capture result from Worker
278278
worker.addEventListener('message', function captureHandler(msg) {
279279
if (msg.data && msg.data.type === 'spector:capture-complete') {
280280
worker.removeEventListener('message', captureHandler);
@@ -285,7 +285,6 @@ if (sessionStorage.getItem(spectorLoadedKey)) {
285285
}
286286
});
287287

288-
// Send trigger directly to Worker
289288
worker.postMessage({
290289
type: 'spector:trigger-capture',
291290
version: 1,
@@ -294,7 +293,7 @@ if (sessionStorage.getItem(spectorLoadedKey)) {
294293
quickCapture: quickCapture,
295294
fullCapture: fullCapture
296295
});
297-
} else {
296+
} else if (canvas) {
298297
spector.captureCanvas(canvas, commandCount, quickCapture, fullCapture);
299298
}
300299
});

0 commit comments

Comments
 (0)