@@ -67,24 +67,25 @@ watch(currentModel, async () => {
6767const showButton = computed (() => supportsVision .value )
6868
6969const handleCapture = async () => {
70- if (isCapturing .value || ! props .attachmentSelectorRef ) return
70+ try {
71+ if (isCapturing .value || ! props .attachmentSelectorRef ) return
7172
72- // Check if adding a screenshot would exceed the combined limit
73- const currentAttachments = props .contextAttachmentStorage ?.attachments ?? []
74- const imageAndScreenshotCount = currentAttachments .filter (
75- (attachment ) => attachment .type === ' image' || attachment .type === ' captured-page' ,
76- ).length
73+ // Permission request should be handled instantly when user clicks the button, so put it here
74+ // Request permission and Capture the visible tab
75+ const dataUrl = await s2bRpc .captureVisibleTab ()
7776
78- if (imageAndScreenshotCount >= MAX_IMAGE_COUNT ) {
79- props .attachmentSelectorRef ?.showErrorMessage (t (' chat.input.attachment_selector.too_many_images' , { max: MAX_IMAGE_COUNT }))
80- return
81- }
77+ // Check if adding a screenshot would exceed the combined limit
78+ const currentAttachments = props .contextAttachmentStorage ?.attachments ?? []
79+ const imageAndScreenshotCount = currentAttachments .filter (
80+ (attachment ) => attachment .type === ' image' || attachment .type === ' captured-page' ,
81+ ).length
8282
83- isCapturing .value = true
83+ if (imageAndScreenshotCount >= MAX_IMAGE_COUNT ) {
84+ props .attachmentSelectorRef ?.showErrorMessage (t (' chat.input.attachment_selector.too_many_images' , { max: MAX_IMAGE_COUNT }))
85+ return
86+ }
8487
85- try {
86- // Capture the visible tab
87- const dataUrl = await s2bRpc .captureVisibleTab ()
88+ isCapturing .value = true
8889
8990 if (! dataUrl ) {
9091 throw new Error (' Failed to capture screenshot' )
0 commit comments