Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements a demo chat feature for the browser extension, adding file upload capabilities, screenshot analysis, and interactive text highlighting functionality to enhance the user experience with mock AI responses.
Key changes include:
- Added file upload functionality with demo AI analysis responses
- Enhanced chat interface with screenshot capabilities and random text highlighting
- Updated UI styling for improved dark theme consistency and better user experience
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| browser-extension/vite.config.ts | Fixed TypeScript compatibility by adding type assertion for crx plugin |
| browser-extension/src/sidepanel/index.html | Added viewport meta tag and page title for better mobile support |
| browser-extension/src/sidepanel/index.css | Complete redesign with modern dark theme and improved layout styles |
| browser-extension/src/sidepanel/App.tsx | Added file upload handler and demo response generation for chat functionality |
| browser-extension/src/sidepanel/App.css | Updated styles for file upload button and cleaned up duplicate CSS rules |
| browser-extension/src/service_worker.ts | Added chat request handling, screenshot capture, and text highlighting features |
| browser-extension/src/content/views/App.tsx | Enhanced floating button with better styling and accessibility |
| browser-extension/src/content/views/App.css | Comprehensive styling improvements for the floating toggle button |
| browser-extension/src/content/test.js | Added test script for verifying content script injection |
| browser-extension/src/content/main.tsx | Improved content script initialization with better error handling |
| browser-extension/src/content.ts | Added message handling for token saving from web app |
| browser-extension/package.json | Updated @crxjs/vite-plugin to newer version |
| browser-extension/manifest.config.ts | Added content script entries for test and token handling |
| apps/web/src/app/token/page.tsx | Created token generation page for extension authentication |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } else if (message.action === "chatResponse" && message.payload) { | ||
| setMessages((prevMessages) => { | ||
| const filteredMessages = prevMessages.filter( | ||
| (msg) => msg.type !== "loading" | ||
| ); | ||
| return [ | ||
| ...filteredMessages, | ||
| { type: "llm", text: message.payload.text }, | ||
| ]; | ||
| }); | ||
| } else if (message.action === "screenshotResponse" && message.payload) { | ||
| setMessages((prevMessages) => { | ||
| const filteredMessages = prevMessages.filter( | ||
| (msg) => msg.type !== "loading" | ||
| ); | ||
| return [ | ||
| ...filteredMessages, | ||
| { type: "llm", text: message.payload.text }, | ||
| ]; | ||
| }); | ||
| } |
There was a problem hiding this comment.
These three message handling blocks contain identical logic for filtering loading messages and adding LLM responses. Consider extracting this into a helper function to reduce code duplication.
| const { tabId } = await chrome.tabs.query({ active: true, currentWindow: true }).then(tabs => ({ tabId: tabs[0]?.id })); | ||
|
|
There was a problem hiding this comment.
This line unnecessarily destructures and reconstructs the tabId. It should be simplified to const [activeTab] = await chrome.tabs.query({ active: true, currentWindow: true }); const tabId = activeTab?.id; for better readability.
| const { tabId } = await chrome.tabs.query({ active: true, currentWindow: true }).then(tabs => ({ tabId: tabs[0]?.id })); | |
| const [activeTab] = await chrome.tabs.query({ active: true, currentWindow: true }); | |
| const tabId = activeTab?.id; |
| let node; | ||
| while (node = walker.nextNode()) { | ||
| textNodes.push(node as Text); |
There was a problem hiding this comment.
Assignment inside the while condition can be confusing and may trigger linting warnings. Consider using a more explicit loop structure: let node = walker.nextNode(); while (node) { textNodes.push(node as Text); node = walker.nextNode(); }
| let node; | |
| while (node = walker.nextNode()) { | |
| textNodes.push(node as Text); | |
| let node = walker.nextNode(); | |
| while (node) { | |
| textNodes.push(node as Text); | |
| node = walker.nextNode(); |
| const isRestrictedDomain = ['extension://', 'chrome://', 'moz-extension://'].some(protocol => | ||
| window.location.href.startsWith(protocol) | ||
| ); |
There was a problem hiding this comment.
The protocol check could be more robust by using window.location.protocol instead of checking the full href. This would be more precise: ['extension:', 'chrome:', 'moz-extension:'].includes(window.location.protocol)
| const isRestrictedDomain = ['extension://', 'chrome://', 'moz-extension://'].some(protocol => | |
| window.location.href.startsWith(protocol) | |
| ); | |
| const isRestrictedDomain = ['extension:', 'chrome:', 'moz-extension:'].includes(window.location.protocol); |
No description provided.