sidebar_position |
---|
3 |
import screencapture from '../../static/img/screenshot-dark.png';
The Screen Capture feature enables users to take screenshots within your application and ask questions about specific UI elements or issues. This guide will walk you through the implementation and usage.
yarn add @openassistant/core @openassistant/ui @nextui-org/react framer-motion html2canvas
First, wrap your application with the ScreenshotWrapper
component:
import { AiAssistant, ScreenshotWrapper } from '@openassistant/ui';
import { useState } from 'react';
function App() {
const [startScreenCapture, setStartScreenCapture] = useState(false);
const [screenCaptured, setScreenCaptured] = useState('');
return (
<ScreenshotWrapper
setScreenCaptured={setScreenCaptured}
startScreenCapture={startScreenCapture}
setStartScreenCapture={setStartScreenCapture}
>
<YourAppContent />
</ScreenshotWrapper>
);
}
Integrate the AI Assistant component with screen capture capabilities:
<AiAssistant
modelProvider="openai"
model="gpt-4"
apiKey={process.env.OPENAI_API_KEY}
welcomeMessage="How can I assist you today?"
enableScreenCapture={true}
screenCapturedBase64={screenCaptured}
onScreenshotClick={() => setStartScreenCapture(true)}
onRemoveScreenshot={() => setScreenCaptured('')}
/>
- Click the "Screenshot to Ask" button in the chat interface
- A semi-transparent overlay will appear
- Click and drag to select the area you want to capture
- Release to complete the capture
- After capturing, the screenshot will be attached to your next message
- Type your question about the captured area
- Send your message to get AI assistance
- Click the "X" button on the screenshot preview to remove it
- Use
onRemoveScreenshot
callback for programmatic removal
<ScreenshotWrapper
setScreenCaptured={setScreenCaptured}
startScreenCapture={startScreenCapture}
setStartScreenCapture={setStartScreenCapture}
saveScreenshot={false} // Enable automatic download
className="custom-wrapper-class"
/>
<AiAssistant
// ... other props
onScreenshotClick={() => {
setStartScreenCapture(true);
console.log('Screenshot capture started');
}}
onRemoveScreenshot={() => {
setScreenCaptured('');
console.log('Screenshot removed');
}}
/>
-
Technical Support
- Capture error messages
- Highlight UI issues
- Document unexpected behavior
-
Data Analysis
- Screenshot charts and graphs
- Capture data visualizations
- Ask questions about specific data points
-
UI/UX Feedback
- Get explanations about interface elements
- Request design improvement suggestions
- Document accessibility concerns
- WebGL Support: Special handling ensures proper capture of WebGL canvases and dynamic content
- Error Handling: Built-in error management with user-friendly feedback
- Accessibility: ARIA labels and keyboard support included