Skip to content

Commit fcc7c94

Browse files
committed
copied extension
1 parent e02e646 commit fcc7c94

File tree

11 files changed

+2241
-3
lines changed

11 files changed

+2241
-3
lines changed

.github/workflows/sync-extension.yml

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ jobs:
111111
echo ""
112112
echo "Directory structure:"
113113
ls -laR . | head -50
114+
echo ""
115+
echo "🔍 Verifying critical files:"
116+
if [ -f "manifest.json" ]; then
117+
echo "✅ manifest.json found ($(wc -c < manifest.json) bytes)"
118+
head -5 manifest.json
119+
else
120+
echo "❌ manifest.json NOT FOUND"
121+
fi
122+
if [ -d "pkg" ]; then
123+
echo "✅ pkg directory found with $(ls -1 pkg | wc -l) files"
124+
else
125+
echo "❌ pkg directory NOT FOUND"
126+
fi
114127
115128
- name: Copy extension files
116129
if: steps.release.outputs.skip != 'true'
@@ -121,11 +134,42 @@ jobs:
121134
# Copy extension files (handle both root and extension-package/ subdirectory)
122135
# Check root first, then extension-package/ subdirectory
123136
if [ -f "extension-temp/manifest.json" ]; then
124-
cp extension-temp/manifest.json src/extension/
137+
size=$(wc -c < extension-temp/manifest.json)
138+
if [ "$size" -gt 0 ]; then
139+
echo "✅ Copying manifest.json ($size bytes)"
140+
cp extension-temp/manifest.json src/extension/
141+
# Verify copy
142+
if [ -f "src/extension/manifest.json" ] && [ "$(wc -c < src/extension/manifest.json)" -gt 0 ]; then
143+
echo "✅ manifest.json copied successfully"
144+
else
145+
echo "❌ manifest.json copy failed or file is empty"
146+
exit 1
147+
fi
148+
else
149+
echo "❌ manifest.json is empty ($size bytes)"
150+
exit 1
151+
fi
125152
elif [ -f "extension-temp/extension-package/manifest.json" ]; then
126-
cp extension-temp/extension-package/manifest.json src/extension/
153+
size=$(wc -c < extension-temp/extension-package/manifest.json)
154+
if [ "$size" -gt 0 ]; then
155+
echo "✅ Copying manifest.json from extension-package/ ($size bytes)"
156+
cp extension-temp/extension-package/manifest.json src/extension/
157+
# Verify copy
158+
if [ -f "src/extension/manifest.json" ] && [ "$(wc -c < src/extension/manifest.json)" -gt 0 ]; then
159+
echo "✅ manifest.json copied successfully"
160+
else
161+
echo "❌ manifest.json copy failed or file is empty"
162+
exit 1
163+
fi
164+
else
165+
echo "❌ manifest.json is empty ($size bytes)"
166+
exit 1
167+
fi
127168
else
128-
echo "⚠️ manifest.json not found"
169+
echo "❌ manifest.json not found in extension-temp/"
170+
echo "Available files:"
171+
find extension-temp -type f | head -20
172+
exit 1
129173
fi
130174
131175
if [ -f "extension-temp/content.js" ]; then

src/extension/background.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// background.js - Service Worker for screenshot capture
2+
// Chrome extensions can only capture screenshots from the background script
3+
// Listen for screenshot requests from content script
4+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
5+
if (request.action === 'captureScreenshot') {
6+
handleScreenshotCapture(sender.tab.id, request.options)
7+
.then(screenshot => {
8+
sendResponse({ success: true, screenshot });
9+
})
10+
.catch(error => {
11+
console.error('[Sentience] Screenshot capture failed:', error);
12+
sendResponse({
13+
success: false,
14+
error: error.message || 'Screenshot capture failed'
15+
});
16+
});
17+
18+
// Return true to indicate we'll send response asynchronously
19+
return true;
20+
}
21+
});
22+
23+
/**
24+
* Capture screenshot of the active tab
25+
* @param {number} tabId - Tab ID to capture
26+
* @param {Object} options - Screenshot options
27+
* @returns {Promise<string>} Base64-encoded PNG data URL
28+
*/
29+
async function handleScreenshotCapture(tabId, options = {}) {
30+
try {
31+
const {
32+
format = 'png', // 'png' or 'jpeg'
33+
quality = 90 // JPEG quality (0-100), ignored for PNG
34+
} = options;
35+
36+
// Capture visible tab as data URL
37+
const dataUrl = await chrome.tabs.captureVisibleTab(null, {
38+
format: format,
39+
quality: quality
40+
});
41+
42+
console.log(`[Sentience] Screenshot captured: ${format}, size: ${dataUrl.length} bytes`);
43+
44+
return dataUrl;
45+
} catch (error) {
46+
console.error('[Sentience] Screenshot error:', error);
47+
throw new Error(`Failed to capture screenshot: ${error.message}`);
48+
}
49+
}
50+
51+
/**
52+
* Optional: Add viewport-specific capture (requires additional setup)
53+
* This would allow capturing specific regions, not just visible area
54+
*/
55+
async function captureRegion(tabId, region) {
56+
// For region capture, you'd need to:
57+
// 1. Capture full visible tab
58+
// 2. Use Canvas API to crop to region
59+
// 3. Return cropped image
60+
61+
// Not implemented in this basic version
62+
throw new Error('Region capture not yet implemented');
63+
}

src/extension/content.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// content.js - ISOLATED WORLD
2+
console.log('[Sentience] Bridge loaded.');
3+
4+
// 1. Pass Extension ID to Main World (So WASM knows where to load from)
5+
document.documentElement.dataset.sentienceExtensionId = chrome.runtime.id;
6+
7+
// 2. Proxy for Screenshots (The only thing Isolated World needs to do)
8+
window.addEventListener('message', (event) => {
9+
// Security check: only accept messages from same window
10+
if (event.source !== window || event.data.type !== 'SENTIENCE_SCREENSHOT_REQUEST') return;
11+
12+
chrome.runtime.sendMessage(
13+
{ action: 'captureScreenshot', options: event.data.options },
14+
(response) => {
15+
window.postMessage({
16+
type: 'SENTIENCE_SCREENSHOT_RESULT',
17+
requestId: event.data.requestId,
18+
screenshot: response?.success ? response.screenshot : null
19+
}, '*');
20+
}
21+
);
22+
});

0 commit comments

Comments
 (0)