+13
-1
@@ -143,6 +143,11 @@ async function extractHits(page, limit) {
|
||||
}, max);
|
||||
}
|
||||
|
||||
async function pageText(page) {
|
||||
const text = await page.locator('body').innerText({ timeout: 2000 }).catch(() => '');
|
||||
return String(text || '').replace(/\n{3,}/g, '\n\n').trim().slice(0, 6000);
|
||||
}
|
||||
|
||||
async function snapshot(page) {
|
||||
let aria = '';
|
||||
try {
|
||||
@@ -150,6 +155,8 @@ async function snapshot(page) {
|
||||
} catch {
|
||||
aria = '';
|
||||
}
|
||||
const text = await pageText(page);
|
||||
const title = await page.title().catch(() => '');
|
||||
const refs = await page.evaluate(() => {
|
||||
const items = [];
|
||||
const nodes = document.querySelectorAll('a, button, input, textarea, select, [role="button"], [role="link"], [contenteditable="true"]');
|
||||
@@ -164,7 +171,12 @@ async function snapshot(page) {
|
||||
}
|
||||
return items;
|
||||
});
|
||||
return { url: page.url(), title: await page.title(), refs, aria: String(aria || '').slice(0, 8000) };
|
||||
const result = { url: page.url(), title, refs, text, aria: String(aria || '').slice(0, 4000) };
|
||||
if (challengeText(title, text)) {
|
||||
result.challenge = true;
|
||||
result.next_action = 'Complete the prompt in the Jarvis browser window, then snapshot again.';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async function locate(page, input) {
|
||||
|
||||
Reference in New Issue
Block a user