browser-assistant 2.9.23 → 2.9.24
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/extension/content.js +18 -2
- package/extension/editor-bridge.js +62 -40
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +1 -1
package/extension/content.js
CHANGED
|
@@ -2110,8 +2110,13 @@ function mountJournalCountdown(signal) {
|
|
|
2110
2110
|
if (ordering) {
|
|
2111
2111
|
const active = () => automation.running && automation.runId === runId && getAutomationContext().mode === 'FULL';
|
|
2112
2112
|
const nativeDrag = (prompt, options, from, to) => safeSendMessage({ action: 'orderingDrag', prompt, options, from, to });
|
|
2113
|
-
|
|
2114
|
-
|
|
2113
|
+
const orderUrl = location.href;
|
|
2114
|
+
const applied = await currentAdapter.applyOrder(document, current, answerIndexes, active, nativeDrag);
|
|
2115
|
+
if (!automation.running || automation.runId !== runId)
|
|
2116
|
+
break;
|
|
2117
|
+
if (!applied) {
|
|
2118
|
+
const visibleQuestion = location.href === orderUrl ? getAuthorizedQuestion() : null;
|
|
2119
|
+
automation.error = orderingReviewMessage(question, answerIndexes, visibleQuestion);
|
|
2115
2120
|
stopAutomation('PAUSED');
|
|
2116
2121
|
break;
|
|
2117
2122
|
}
|
|
@@ -2849,6 +2854,17 @@ function mountJournalCountdown(signal) {
|
|
|
2849
2854
|
throw new Error('The verified answer did not match the displayed options exactly.');
|
|
2850
2855
|
}
|
|
2851
2856
|
}
|
|
2857
|
+
function orderingReviewMessage(question, order, current) {
|
|
2858
|
+
const message = 'The page did not confirm the drag.';
|
|
2859
|
+
if (current?.type !== 'ordering' || current.text !== question.text || current.options.length !== order.length) {
|
|
2860
|
+
return message + ' Check the current rows before submitting.';
|
|
2861
|
+
}
|
|
2862
|
+
const positions = order.map(index => current.options.findIndex(option => option.text === question.options[index].text) + 1);
|
|
2863
|
+
if (positions.includes(0) || new Set(positions).size !== order.length) {
|
|
2864
|
+
return message + ' Check the current rows before submitting.';
|
|
2865
|
+
}
|
|
2866
|
+
return message + ` Arrange the current rows in the order ${positions.join(' → ')}.`;
|
|
2867
|
+
}
|
|
2852
2868
|
async function prepareVisionQuestionContext() {
|
|
2853
2869
|
const context = { url: location.href, text: '', question: getAuthorizedQuestion() };
|
|
2854
2870
|
if (!context.question || context.question.type === 'code') {
|
|
@@ -286,8 +286,7 @@ function browserAssistantReadMcqSnippets() {
|
|
|
286
286
|
return { ok: false, error: error.message };
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
//
|
|
290
|
-
// native DataTransfer object only when these events originate in this world.
|
|
289
|
+
// Run in the page's main world so the practice page receives the drag data.
|
|
291
290
|
async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
292
291
|
try {
|
|
293
292
|
const normalize = value => (value || '').replace(/\s+/g, ' ').trim();
|
|
@@ -307,7 +306,10 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
307
306
|
return [];
|
|
308
307
|
const visible = [...question.querySelectorAll('.drag-and-drop-option-label')]
|
|
309
308
|
.filter(label => label.getClientRects().length)
|
|
310
|
-
.map(label => ({
|
|
309
|
+
.map(label => ({
|
|
310
|
+
label, row: label.parentElement, text: normalize(label.textContent),
|
|
311
|
+
handle: label.parentElement?.querySelector('.drag-icon-container[draggable="true"]'),
|
|
312
|
+
}));
|
|
311
313
|
return visible.length === expectedTexts.length && visible.every(row => uniqueTexts.has(row.text) && row.handle)
|
|
312
314
|
&& new Set(visible.map(row => row.text)).size === uniqueTexts.size ? visible : [];
|
|
313
315
|
};
|
|
@@ -317,45 +319,65 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
317
319
|
return { ok: false };
|
|
318
320
|
if (from === to)
|
|
319
321
|
return { ok: true };
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
const
|
|
322
|
+
const moving = before[from].text;
|
|
323
|
+
const destination = before[to].text;
|
|
324
|
+
const findRow = text => rows().find(row => row.text === text);
|
|
325
|
+
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
326
|
+
const center = node => {
|
|
325
327
|
const rect = node.getBoundingClientRect();
|
|
326
|
-
node.
|
|
327
|
-
bubbles: true, cancelable: true, dataTransfer,
|
|
328
|
-
clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2,
|
|
329
|
-
}));
|
|
328
|
+
return { node, clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2 };
|
|
330
329
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
330
|
+
for (const useRowBody of [true, false]) {
|
|
331
|
+
const current = rows();
|
|
332
|
+
if (current.length !== before.length || current.some((row, index) => row.text !== expectedTexts[index]))
|
|
333
|
+
break;
|
|
334
|
+
const source = current[from].handle;
|
|
335
|
+
const dataTransfer = new DataTransfer();
|
|
336
|
+
dataTransfer.setData('text/plain', moving);
|
|
337
|
+
dataTransfer.effectAllowed = 'move';
|
|
338
|
+
const send = ({ node, clientX, clientY }, type) => node.dispatchEvent(new DragEvent(type, {
|
|
339
|
+
bubbles: true, cancelable: true, dataTransfer, clientX, clientY,
|
|
340
|
+
}));
|
|
341
|
+
const target = () => {
|
|
342
|
+
const row = findRow(destination);
|
|
343
|
+
if (!row)
|
|
344
|
+
return null;
|
|
345
|
+
if (!useRowBody)
|
|
346
|
+
return center(row.handle);
|
|
347
|
+
const { clientX } = center(row.label);
|
|
348
|
+
const rect = row.row.getBoundingClientRect();
|
|
349
|
+
const clientY = rect.top + rect.height * (from > to ? 0.25 : 0.75);
|
|
350
|
+
const hit = document.elementFromPoint?.(clientX, clientY);
|
|
351
|
+
return { node: hit && row.row.contains(hit) ? hit : row.label, clientX, clientY };
|
|
352
|
+
};
|
|
353
|
+
if (!send(center(source), 'dragstart'))
|
|
354
|
+
break;
|
|
355
|
+
try {
|
|
356
|
+
// A drag handler can render fresh row nodes between events.
|
|
357
|
+
await wait(220);
|
|
358
|
+
dataTransfer.dropEffect = 'move';
|
|
359
|
+
const entered = target();
|
|
360
|
+
if (!entered)
|
|
361
|
+
break;
|
|
362
|
+
send(entered, 'dragenter');
|
|
363
|
+
const hovered = target();
|
|
364
|
+
if (!hovered)
|
|
365
|
+
break;
|
|
366
|
+
send(hovered, 'dragover');
|
|
367
|
+
await wait(220);
|
|
368
|
+
const dropped = target();
|
|
369
|
+
if (!dropped)
|
|
370
|
+
break;
|
|
371
|
+
send(dropped, 'drop');
|
|
372
|
+
}
|
|
373
|
+
finally {
|
|
374
|
+
send(center(findRow(moving)?.handle || source), 'dragend');
|
|
375
|
+
}
|
|
376
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
377
|
+
await wait(160);
|
|
378
|
+
if (rows()[to]?.text === moving)
|
|
379
|
+
return { ok: true };
|
|
380
|
+
}
|
|
359
381
|
}
|
|
360
382
|
return { ok: false };
|
|
361
383
|
}
|
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
package/server/main.py
CHANGED
|
@@ -194,7 +194,7 @@ async def lifespan(_app: FastAPI):
|
|
|
194
194
|
client.close()
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
197
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.24", lifespan=lifespan)
|
|
198
198
|
install_local_guards(app)
|
|
199
199
|
|
|
200
200
|
@app.exception_handler(HTTPException)
|