browser-assistant 2.9.3 → 2.9.4
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 +2 -0
- package/extension/automation-policy.js +21 -2
- package/extension/background.js +13 -5
- package/extension/content.js +389 -53
- package/extension/detached-panel-background.js +101 -0
- package/extension/detached-panel.html +18 -0
- package/extension/detached-panel.js +201 -0
- package/extension/journal-automation.js +11 -6
- package/extension/manifest.json +1 -1
- package/extension/popup.html +2 -0
- package/extension/popup.js +24 -0
- package/extension/styles.css +89 -0
- package/package.json +7 -2
- package/server/main.py +62 -2
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ AI answers can be wrong. Automation can change or submit page content: use it on
|
|
|
16
16
|
|
|
17
17
|
## First run
|
|
18
18
|
|
|
19
|
+
For a separate assistant window and supported recording setup, see the [Separate Panel Window guide](docs/SEPARATE_PANEL.md).
|
|
20
|
+
|
|
19
21
|
### Continuous coding batch
|
|
20
22
|
|
|
21
23
|
On CCBP `/problems-set`, start on page 1 and keep both **Not Attempted** and
|
|
@@ -199,6 +199,7 @@
|
|
|
199
199
|
groups.set(key, []);
|
|
200
200
|
groups.get(key).push(control);
|
|
201
201
|
}
|
|
202
|
+
const radioCandidates = [];
|
|
202
203
|
for (const group of groups.values()) {
|
|
203
204
|
if (group.length < 2)
|
|
204
205
|
continue;
|
|
@@ -211,6 +212,7 @@
|
|
|
211
212
|
const input = control.matches('input[type="radio"],input[type="checkbox"]') ? control : control.querySelector('input[type="radio"],input[type="checkbox"]');
|
|
212
213
|
const label = input?.labels?.[0]
|
|
213
214
|
|| (input?.id ? doc.querySelector(`[for="${CSS.escape(input.id)}"]`) : null)
|
|
215
|
+
|| input?.closest('label')
|
|
214
216
|
|| (control.matches('label') ? control : null);
|
|
215
217
|
const optionControl = label && input ? label : control;
|
|
216
218
|
const optionText = textOf(label) || textOf(control) || control.getAttribute('aria-label') || control.getAttribute('value') || '';
|
|
@@ -229,6 +231,9 @@
|
|
|
229
231
|
const heading = fieldset?.querySelector('legend')
|
|
230
232
|
|| radioGroup?.querySelector('h1,h2,h3,h4,[role="heading"]')
|
|
231
233
|
|| container.querySelector?.('h1,h2,h3,h4,[role="heading"]');
|
|
234
|
+
const localPrompt = [...optionScope.querySelectorAll('p,h1,h2,h3,h4,[role="heading"],div,span')]
|
|
235
|
+
.find(node => !node.querySelector('input[type="radio"],input[type="checkbox"],[role="radio"],[role="checkbox"]')
|
|
236
|
+
&& textOf(node).length >= 12 && textOf(node).length <= 1200);
|
|
232
237
|
let nearbyPrompt = '';
|
|
233
238
|
let branch = optionScope;
|
|
234
239
|
for (let ancestor = optionScope; ancestor && ancestor !== doc.body && !nearbyPrompt; ancestor = ancestor.parentElement) {
|
|
@@ -245,7 +250,7 @@
|
|
|
245
250
|
if (ancestor === doc.body)
|
|
246
251
|
break;
|
|
247
252
|
}
|
|
248
|
-
const text = textOf(heading) || labelledText(radioGroup) || labelledText(container)
|
|
253
|
+
const text = textOf(heading) || textOf(localPrompt) || labelledText(radioGroup) || labelledText(container)
|
|
249
254
|
|| radioGroup?.getAttribute('aria-label') || container.getAttribute('aria-label') || nearbyPrompt;
|
|
250
255
|
if (!text.trim())
|
|
251
256
|
continue;
|
|
@@ -286,10 +291,24 @@
|
|
|
286
291
|
const identityRegion = promptRegion?.cloneNode(true);
|
|
287
292
|
identityRegion?.querySelectorAll('pre,code,.ace_editor,.CodeMirror,.monaco-editor,button,input,textarea,script,style').forEach(node => node.remove());
|
|
288
293
|
const identityText = identityRegion ? textOf(identityRegion) : text.trim();
|
|
289
|
-
|
|
294
|
+
radioCandidates.push({
|
|
290
295
|
text: questionText, identityText: identityText || text.trim(), options, visualRegion: sourceRegion,
|
|
291
296
|
selectionType: group[0].matches('input[type="checkbox"],[role="checkbox"]') ? 'multiple' : 'single',
|
|
292
297
|
form: container.matches('form') ? container : container.closest('form'), container: optionScope,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (radioCandidates.length === 1)
|
|
301
|
+
return radioCandidates[0];
|
|
302
|
+
if (radioCandidates.length > 1) {
|
|
303
|
+
const unanswered = radioCandidates.find(candidate => !candidate.options.some(option => option.isSelected?.() || option.input?.checked));
|
|
304
|
+
const active = unanswered || radioCandidates[0];
|
|
305
|
+
const pageCopy = doc.body.cloneNode(true);
|
|
306
|
+
pageCopy.querySelectorAll('#assistant-root,input,button,[role="button"],script,style').forEach(node => node.remove());
|
|
307
|
+
return {
|
|
308
|
+
...active,
|
|
309
|
+
type: 'compound-mcq',
|
|
310
|
+
compoundQuestions: radioCandidates,
|
|
311
|
+
compoundContext: textOf(pageCopy).slice(0, 12000),
|
|
293
312
|
};
|
|
294
313
|
}
|
|
295
314
|
// Letter-badge cards (A, B, C...) do not always expose native
|
package/extension/background.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Background script for Browser Assistant
|
|
2
|
-
importScripts('editor-bridge.js');
|
|
2
|
+
importScripts('editor-bridge.js', 'detached-panel-background.js');
|
|
3
3
|
// Local unpacked development updates: only reload when the files in Chrome's
|
|
4
4
|
// own extension folder match the workspace release, and every running task is idle.
|
|
5
5
|
let updateCheckRunning = false;
|
|
@@ -130,6 +130,9 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
|
130
130
|
sendResponse({ error: 'Invalid extension message' });
|
|
131
131
|
return false;
|
|
132
132
|
}
|
|
133
|
+
if (['panel:open', 'panel:snapshot', 'panel:action', 'panel:return', 'panel:target-status'].includes(request.action)) {
|
|
134
|
+
return browserAssistantDetachedMessage(request, sender, sendResponse);
|
|
135
|
+
}
|
|
133
136
|
if (request.action === 'journalCountdowns' && sender.id === chrome.runtime.id) {
|
|
134
137
|
chrome.storage.local.get().then(data => sendResponse(activeJournalTimers(data)))
|
|
135
138
|
.catch(() => sendResponse([]));
|
|
@@ -284,8 +287,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
|
284
287
|
}
|
|
285
288
|
// A tab can lose focus while capture is queued. Never capture another
|
|
286
289
|
// tab/window and send that screenshot with the requesting page's URL.
|
|
287
|
-
chrome.tabs.query({ active: true, windowId: sender.tab.windowId })
|
|
288
|
-
|
|
290
|
+
const activeTab = () => chrome.tabs.query({ active: true, windowId: sender.tab.windowId });
|
|
291
|
+
const isTarget = active => active.length === 1 && active[0].id === sender.tab.id
|
|
292
|
+
&& (!request.url || active[0].url === request.url);
|
|
293
|
+
activeTab().then(active => {
|
|
294
|
+
if (!isTarget(active)) {
|
|
289
295
|
sendResponse({ error: 'The requesting tab is no longer active. Focus it and try Vision Scan again.' });
|
|
290
296
|
return;
|
|
291
297
|
}
|
|
@@ -295,7 +301,9 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
|
295
301
|
sendResponse({ error: chrome.runtime.lastError.message });
|
|
296
302
|
}
|
|
297
303
|
else {
|
|
298
|
-
sendResponse({ dataUrl
|
|
304
|
+
void activeTab().then(current => sendResponse(isTarget(current) ? { dataUrl }
|
|
305
|
+
: { error: 'The selected tab changed during capture. Try Vision Scan again.' }))
|
|
306
|
+
.catch(() => sendResponse({ error: 'Could not verify the active screenshot tab.' }));
|
|
299
307
|
}
|
|
300
308
|
});
|
|
301
309
|
}).catch(() => sendResponse({ error: 'Could not verify the active screenshot tab.' }));
|
|
@@ -303,7 +311,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
|
303
311
|
}
|
|
304
312
|
if (request.action === "apiRequest") {
|
|
305
313
|
const allowedMethods = { '/health': ['GET'], '/solve': ['POST'], '/solve-vision': ['POST'],
|
|
306
|
-
'/history': ['GET', 'POST', 'DELETE'], '/journal': ['POST'] };
|
|
314
|
+
'/history': ['GET', 'POST', 'DELETE'], '/automation-history': ['GET', 'PUT'], '/journal': ['POST'] };
|
|
307
315
|
const method = request.method || 'POST';
|
|
308
316
|
if (sender.id !== chrome.runtime.id || !allowedMethods[request.path]?.includes(method)) {
|
|
309
317
|
sendResponse({ error: "Blocked API sender, path or method" });
|