Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 1 addition & 63 deletions sentience/extension/background.js
Original file line number Diff line number Diff line change
@@ -1,63 +1 @@
// background.js - Service Worker for screenshot capture
// Chrome extensions can only capture screenshots from the background script
// Listen for screenshot requests from content script
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'captureScreenshot') {
handleScreenshotCapture(sender.tab.id, request.options)
.then(screenshot => {
sendResponse({ success: true, screenshot });
})
.catch(error => {
console.error('[Sentience] Screenshot capture failed:', error);
sendResponse({
success: false,
error: error.message || 'Screenshot capture failed'
});
});

// Return true to indicate we'll send response asynchronously
return true;
}
});

/**
* Capture screenshot of the active tab
* @param {number} tabId - Tab ID to capture
* @param {Object} options - Screenshot options
* @returns {Promise<string>} Base64-encoded PNG data URL
*/
async function handleScreenshotCapture(tabId, options = {}) {
try {
const {
format = 'png', // 'png' or 'jpeg'
quality = 90 // JPEG quality (0-100), ignored for PNG
} = options;

// Capture visible tab as data URL
const dataUrl = await chrome.tabs.captureVisibleTab(null, {
format: format,
quality: quality
});

console.log(`[Sentience] Screenshot captured: ${format}, size: ${dataUrl.length} bytes`);

return dataUrl;
} catch (error) {
console.error('[Sentience] Screenshot error:', error);
throw new Error(`Failed to capture screenshot: ${error.message}`);
}
}

/**
* Optional: Add viewport-specific capture (requires additional setup)
* This would allow capturing specific regions, not just visible area
*/
async function captureRegion(tabId, region) {
// For region capture, you'd need to:
// 1. Capture full visible tab
// 2. Use Canvas API to crop to region
// 3. Return cropped image

// Not implemented in this basic version
throw new Error('Region capture not yet implemented');
}
Not Found
23 changes: 1 addition & 22 deletions sentience/extension/content.js
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
// content.js - ISOLATED WORLD
console.log('[Sentience] Bridge loaded.');

// 1. Pass Extension ID to Main World (So WASM knows where to load from)
document.documentElement.dataset.sentienceExtensionId = chrome.runtime.id;

// 2. Proxy for Screenshots (The only thing Isolated World needs to do)
window.addEventListener('message', (event) => {
// Security check: only accept messages from same window
if (event.source !== window || event.data.type !== 'SENTIENCE_SCREENSHOT_REQUEST') return;

chrome.runtime.sendMessage(
{ action: 'captureScreenshot', options: event.data.options },
(response) => {
window.postMessage({
type: 'SENTIENCE_SCREENSHOT_RESULT',
requestId: event.data.requestId,
screenshot: response?.success ? response.screenshot : null
}, '*');
}
);
});
Not Found
Loading
Loading