feat: MCP Browser v3.1.1 - 56+ tools, visual overlays, fixes
- Added 9 new tools: visual overlay, highlight, toast, drag-drop, etc. - Fixed evaluateJS to support function arguments - Fixed hover for non-visible elements - Fixed storage operations with try/catch - Added 10 new wait tools: clickable, element visible, text - Fixed tool name mapping in server.js for MCP protocol - Updated README with 60+ tools documentation - Version bump to 3.1.1
This commit is contained in:
+32
-24
@@ -3,29 +3,37 @@ const browser = require('../browser');
|
||||
module.exports = async ({ data }) => {
|
||||
if (!data) throw new Error('Data é obrigatória');
|
||||
await browser.start();
|
||||
const result = await browser.evaluateJS((formData) => {
|
||||
const inputs = Array.from(document.querySelectorAll('input, textarea, select'));
|
||||
const filled = [];
|
||||
inputs.forEach(input => {
|
||||
const key = Object.keys(formData).find(k =>
|
||||
(input.name && input.name.toLowerCase().includes(k.toLowerCase())) ||
|
||||
(input.placeholder || '').toLowerCase().includes(k.toLowerCase()) ||
|
||||
(input.id || '').toLowerCase().includes(k.toLowerCase()) ||
|
||||
(input.getAttribute('aria-label') || '').toLowerCase().includes(k.toLowerCase())
|
||||
);
|
||||
if (key) {
|
||||
const value = formData[key];
|
||||
const nativeSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set;
|
||||
const nativeTextAreaSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value')?.set;
|
||||
if (input.tagName === 'INPUT' && nativeSetter) nativeSetter.call(input, value);
|
||||
else if (input.tagName === 'TEXTAREA' && nativeTextAreaSetter) nativeTextAreaSetter.call(input, value);
|
||||
else input.value = value;
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
filled.push({ field: input.name || input.id || input.placeholder || 'unknown', value });
|
||||
|
||||
const formDataJson = JSON.stringify(data).replace(/'/g, "\\'");
|
||||
|
||||
const result = await browser.evaluateJS(`
|
||||
(function() {
|
||||
try {
|
||||
var formData = JSON.parse('${formDataJson}');
|
||||
var inputs = Array.from(document.querySelectorAll('input, textarea, select'));
|
||||
var filled = [];
|
||||
inputs.forEach(function(input) {
|
||||
var keys = Object.keys(formData);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var k = keys[i];
|
||||
var match = input.name && input.name.toLowerCase().indexOf(k.toLowerCase()) >= 0 ||
|
||||
input.placeholder && input.placeholder.toLowerCase().indexOf(k.toLowerCase()) >= 0 ||
|
||||
input.id && input.id.toLowerCase().indexOf(k.toLowerCase()) >= 0;
|
||||
if (match) {
|
||||
input.value = formData[k];
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
filled.push({ field: input.name || input.id || 'unknown', value: formData[k] });
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return filled;
|
||||
} catch (e) {
|
||||
return { error: e.message };
|
||||
}
|
||||
});
|
||||
return filled;
|
||||
}, data);
|
||||
return { success: true, action: 'fill_form_auto', filled: result, count: result.length };
|
||||
})()
|
||||
`);
|
||||
|
||||
return { success: true, action: 'fill_form_auto', filled: result, count: Array.isArray(result) ? result.length : 0 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user