Login failed: puppeteer is not defined - Follow Up Deployment
Browse files- index.html +109 -19
index.html
CHANGED
@@ -223,7 +223,14 @@
|
|
223 |
</div>
|
224 |
</div>
|
225 |
|
|
|
226 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
// LLM Model Configuration
|
228 |
const llmConfig = {
|
229 |
model: "DeepHermes-3-Llama-3-8B-Preview",
|
@@ -305,28 +312,31 @@
|
|
305 |
const settingsModal = document.getElementById('settingsModal');
|
306 |
const closeSettings = document.getElementById('closeSettings');
|
307 |
|
308 |
-
//
|
309 |
-
function
|
310 |
conversationList.innerHTML = '';
|
311 |
-
conversations.forEach(convo => {
|
312 |
const convoElement = document.createElement('div');
|
313 |
convoElement.className = `p-3 border-b border-gray-200 hover:bg-gray-100 cursor-pointer transition ${convo.unread > 0 ? 'bg-blue-50' : 'bg-white'}`;
|
314 |
convoElement.innerHTML = `
|
315 |
<div class="flex items-center space-x-3">
|
316 |
<div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center text-purple-600 font-semibold">
|
317 |
-
${convo.
|
318 |
</div>
|
319 |
<div class="flex-grow">
|
320 |
<div class="flex justify-between items-center">
|
321 |
<h3 class="font-semibold">${convo.name}</h3>
|
322 |
-
<span class="text-xs text-gray-500"
|
323 |
</div>
|
324 |
-
<p class="text-sm text-gray-600 truncate">${convo.
|
325 |
</div>
|
326 |
${convo.unread > 0 ? `<span class="w-5 h-5 bg-purple-500 text-white text-xs rounded-full flex items-center justify-center">${convo.unread}</span>` : ''}
|
327 |
</div>
|
328 |
`;
|
329 |
-
convoElement.addEventListener('click', () =>
|
|
|
|
|
|
|
330 |
conversationList.appendChild(convoElement);
|
331 |
});
|
332 |
}
|
@@ -451,6 +461,66 @@
|
|
451 |
}
|
452 |
}
|
453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
// Update last refresh time
|
455 |
function updateRefreshTime() {
|
456 |
const now = new Date();
|
@@ -478,7 +548,7 @@
|
|
478 |
const igUsername = document.getElementById('igUsername');
|
479 |
const igPassword = document.getElementById('igPassword');
|
480 |
|
481 |
-
//
|
482 |
async function loginToInstagram() {
|
483 |
const username = igUsername.value.trim();
|
484 |
const password = igPassword.value.trim();
|
@@ -488,31 +558,51 @@
|
|
488 |
return;
|
489 |
}
|
490 |
|
491 |
-
// Show loading state
|
492 |
loginBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Logging in...';
|
493 |
loginBtn.disabled = true;
|
494 |
|
495 |
try {
|
496 |
-
//
|
497 |
-
|
498 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
|
500 |
// Hide login, show main app
|
501 |
loginModal.classList.add('hidden');
|
502 |
mainApp.classList.remove('hidden');
|
503 |
|
504 |
-
//
|
505 |
-
|
506 |
-
updateRefreshTime();
|
507 |
|
508 |
-
// For demo purposes, load the first conversation
|
509 |
-
if (conversations.length > 0) {
|
510 |
-
loadMessages(conversations[0].id);
|
511 |
-
}
|
512 |
} catch (error) {
|
513 |
alert('Login failed: ' + error.message);
|
514 |
loginBtn.innerHTML = 'Login to Instagram';
|
515 |
loginBtn.disabled = false;
|
|
|
516 |
}
|
517 |
}
|
518 |
|
|
|
223 |
</div>
|
224 |
</div>
|
225 |
|
226 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/esm/puppeteer-core-browser.js"></script>
|
227 |
<script>
|
228 |
+
// Global variables
|
229 |
+
let browser;
|
230 |
+
let page;
|
231 |
+
let currentConversationId;
|
232 |
+
let lastMessages = {};
|
233 |
+
|
234 |
// LLM Model Configuration
|
235 |
const llmConfig = {
|
236 |
model: "DeepHermes-3-Llama-3-8B-Preview",
|
|
|
312 |
const settingsModal = document.getElementById('settingsModal');
|
313 |
const closeSettings = document.getElementById('closeSettings');
|
314 |
|
315 |
+
// Update conversation list with real data
|
316 |
+
function updateConversationList(conversations) {
|
317 |
conversationList.innerHTML = '';
|
318 |
+
conversations.forEach((convo, index) => {
|
319 |
const convoElement = document.createElement('div');
|
320 |
convoElement.className = `p-3 border-b border-gray-200 hover:bg-gray-100 cursor-pointer transition ${convo.unread > 0 ? 'bg-blue-50' : 'bg-white'}`;
|
321 |
convoElement.innerHTML = `
|
322 |
<div class="flex items-center space-x-3">
|
323 |
<div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center text-purple-600 font-semibold">
|
324 |
+
${convo.name.charAt(0)}
|
325 |
</div>
|
326 |
<div class="flex-grow">
|
327 |
<div class="flex justify-between items-center">
|
328 |
<h3 class="font-semibold">${convo.name}</h3>
|
329 |
+
<span class="text-xs text-gray-500">Just now</span>
|
330 |
</div>
|
331 |
+
<p class="text-sm text-gray-600 truncate">${convo.lastMsg}</p>
|
332 |
</div>
|
333 |
${convo.unread > 0 ? `<span class="w-5 h-5 bg-purple-500 text-white text-xs rounded-full flex items-center justify-center">${convo.unread}</span>` : ''}
|
334 |
</div>
|
335 |
`;
|
336 |
+
convoElement.addEventListener('click', () => {
|
337 |
+
currentConversationId = index;
|
338 |
+
loadMessages(index);
|
339 |
+
});
|
340 |
conversationList.appendChild(convoElement);
|
341 |
});
|
342 |
}
|
|
|
461 |
}
|
462 |
}
|
463 |
|
464 |
+
// Monitor Instagram DMs in real-time
|
465 |
+
async function monitorDMs() {
|
466 |
+
setInterval(async () => {
|
467 |
+
try {
|
468 |
+
// Get all conversations
|
469 |
+
const conversations = await page.evaluate(() => {
|
470 |
+
const items = Array.from(document.querySelectorAll('div[role="button"]'));
|
471 |
+
return items.map(item => {
|
472 |
+
const name = item.querySelector('span')?.innerText || 'Unknown';
|
473 |
+
const lastMsg = item.querySelector('div > div > div > div > div > span')?.innerText || '';
|
474 |
+
const unread = item.querySelector('div[aria-label="Unread"]') ? 1 : 0;
|
475 |
+
return { name, lastMsg, unread };
|
476 |
+
});
|
477 |
+
});
|
478 |
+
|
479 |
+
// Update UI with real conversations
|
480 |
+
updateConversationList(conversations);
|
481 |
+
|
482 |
+
// Check for new messages in current conversation
|
483 |
+
if (currentConversationId) {
|
484 |
+
const messages = await getMessages(currentConversationId);
|
485 |
+
checkForNewMessages(currentConversationId, messages);
|
486 |
+
}
|
487 |
+
|
488 |
+
updateRefreshTime();
|
489 |
+
} catch (error) {
|
490 |
+
console.error('Error monitoring DMs:', error);
|
491 |
+
}
|
492 |
+
}, 5000); // Check every 5 seconds
|
493 |
+
}
|
494 |
+
|
495 |
+
// Get messages from a conversation
|
496 |
+
async function getMessages(convoId) {
|
497 |
+
// Implementation to get messages from Instagram
|
498 |
+
// This would use page.evaluate() to scrape the chat window
|
499 |
+
return []; // Return array of message objects
|
500 |
+
}
|
501 |
+
|
502 |
+
// Check for and respond to new messages
|
503 |
+
async function checkForNewMessages(convoId, messages) {
|
504 |
+
const lastMessage = messages[messages.length - 1];
|
505 |
+
if (!lastMessages[convoId] || lastMessages[convoId] !== lastMessage.id) {
|
506 |
+
lastMessages[convoId] = lastMessage.id;
|
507 |
+
|
508 |
+
if (lastMessage.sender !== 'me') {
|
509 |
+
// Get LLM response
|
510 |
+
const response = await getBotResponse(lastMessage.text);
|
511 |
+
|
512 |
+
// Send response back to Instagram
|
513 |
+
await sendInstagramMessage(convoId, response);
|
514 |
+
}
|
515 |
+
}
|
516 |
+
}
|
517 |
+
|
518 |
+
// Send message to Instagram
|
519 |
+
async function sendInstagramMessage(convoId, text) {
|
520 |
+
// Implementation to send message via Puppeteer
|
521 |
+
// This would find the message input and send the text
|
522 |
+
}
|
523 |
+
|
524 |
// Update last refresh time
|
525 |
function updateRefreshTime() {
|
526 |
const now = new Date();
|
|
|
548 |
const igUsername = document.getElementById('igUsername');
|
549 |
const igPassword = document.getElementById('igPassword');
|
550 |
|
551 |
+
// Real Instagram login function
|
552 |
async function loginToInstagram() {
|
553 |
const username = igUsername.value.trim();
|
554 |
const password = igPassword.value.trim();
|
|
|
558 |
return;
|
559 |
}
|
560 |
|
|
|
561 |
loginBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Logging in...';
|
562 |
loginBtn.disabled = true;
|
563 |
|
564 |
try {
|
565 |
+
// Connect to browser instance (you'll need Chrome installed)
|
566 |
+
browser = await puppeteer.connect({
|
567 |
+
browserURL: 'http://127.0.0.1:9222',
|
568 |
+
defaultViewport: null
|
569 |
+
});
|
570 |
+
|
571 |
+
page = (await browser.pages())[0] || await browser.newPage();
|
572 |
+
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
|
573 |
+
|
574 |
+
// Navigate to Instagram login
|
575 |
+
await page.goto('https://www.instagram.com/accounts/login/', { waitUntil: 'networkidle2' });
|
576 |
+
|
577 |
+
// Fill login form
|
578 |
+
await page.type('input[name="username"]', username);
|
579 |
+
await page.type('input[name="password"]', password);
|
580 |
+
await page.click('button[type="submit"]');
|
581 |
+
|
582 |
+
// Wait for login to complete
|
583 |
+
await page.waitForNavigation({ waitUntil: 'networkidle2' });
|
584 |
+
|
585 |
+
// Check for login errors
|
586 |
+
const loginError = await page.$('p[id="slfErrorAlert"]');
|
587 |
+
if (loginError) {
|
588 |
+
throw new Error('Invalid username or password');
|
589 |
+
}
|
590 |
+
|
591 |
+
// Go to DMs
|
592 |
+
await page.goto('https://www.instagram.com/direct/inbox/', { waitUntil: 'networkidle2' });
|
593 |
|
594 |
// Hide login, show main app
|
595 |
loginModal.classList.add('hidden');
|
596 |
mainApp.classList.remove('hidden');
|
597 |
|
598 |
+
// Start monitoring DMs
|
599 |
+
monitorDMs();
|
|
|
600 |
|
|
|
|
|
|
|
|
|
601 |
} catch (error) {
|
602 |
alert('Login failed: ' + error.message);
|
603 |
loginBtn.innerHTML = 'Login to Instagram';
|
604 |
loginBtn.disabled = false;
|
605 |
+
if (browser) await browser.close();
|
606 |
}
|
607 |
}
|
608 |
|