feat: MCP Browser - servidor MCP para automação de navegador com Playwright
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
const browser = require('../browser');
|
||||
|
||||
module.exports = async ({ url }) => {
|
||||
if (!url) {
|
||||
throw new Error('URL é obrigatória');
|
||||
}
|
||||
|
||||
await browser.start();
|
||||
const p = await browser.ensurePage();
|
||||
|
||||
const currentUrl = p.url();
|
||||
|
||||
if (currentUrl && currentUrl !== 'about:blank') {
|
||||
if (currentUrl.includes(new URL(url).hostname)) {
|
||||
await p.goto(url, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 30000
|
||||
});
|
||||
await p.waitForTimeout(1500);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
url,
|
||||
title: await p.title(),
|
||||
tab: 'reused'
|
||||
};
|
||||
}
|
||||
|
||||
const newPage = await browser.newTab();
|
||||
await newPage.goto(url, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 30000
|
||||
});
|
||||
await newPage.waitForTimeout(1500);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
url,
|
||||
title: await newPage.title(),
|
||||
tab: 'new'
|
||||
};
|
||||
}
|
||||
|
||||
await p.goto(url, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 30000
|
||||
});
|
||||
await p.waitForTimeout(1500);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
url,
|
||||
title: await p.title(),
|
||||
tab: 'existing'
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user