[DevTools][AI Assistant] Allow Users To Paste Images Directly From Clipboard [devtools/devtools-frontend : main]

0 views
Skip to first unread message

Samiya Caur (Gerrit)

unread,
Dec 22, 2025, 5:22:53 AM (4 days ago) Dec 22
to Emir D, Ergün Erdoğmuş, devtools-rev...@chromium.org
Attention needed from Emir D

Samiya Caur added 2 comments

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Samiya Caur . unresolved

Thank you! Can you also look into adding a test for this?

File front_end/panels/ai_assistance/components/ChatInput.ts
Line 553, Patchset 1 (Latest): #handlePaste = (event: ClipboardEvent): void => {
Samiya Caur . unresolved

nit: since we only handle pasting of image, can we rename this to something more specific?

same for `onPaste`

Open in Gerrit

Related details

Attention is currently required from:
  • Emir D
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: devtools/devtools-frontend
Gerrit-Branch: main
Gerrit-Change-Id: I2ce04b56a3114507d3728aed2429f98f6a2a1db9
Gerrit-Change-Number: 7278223
Gerrit-PatchSet: 1
Gerrit-Owner: Emir D <emr...@gmail.com>
Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
Gerrit-Reviewer: Samiya Caur <sam...@chromium.org>
Gerrit-Attention: Emir D <emr...@gmail.com>
Gerrit-Comment-Date: Mon, 22 Dec 2025 10:22:49 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Emir D (Gerrit)

unread,
Dec 22, 2025, 10:53:49 AM (4 days ago) Dec 22
to Samiya Caur, Ergün Erdoğmuş, devtools-rev...@chromium.org
Attention needed from Samiya Caur

Emir D added 3 comments

Patchset-level comments
File-level comment, Patchset 1:
Samiya Caur . resolved

Thank you! Can you also look into adding a test for this?

Emir D

Hi, I updated the related codes and added the tests to ChatInput.test.ts file.

File-level comment, Patchset 2 (Latest):
Emir D . resolved

The code has been updated due to comments.

File front_end/panels/ai_assistance/components/ChatInput.ts
Line 553, Patchset 1: #handlePaste = (event: ClipboardEvent): void => {
Samiya Caur . resolved

nit: since we only handle pasting of image, can we rename this to something more specific?

same for `onPaste`

Emir D

Hi, I changed the related method names and maked more informational and specific. See the changes;

- ChatInput.ts: 
- onPaste -> onImagePaste
- handlePaste -> handleImagePaste
- ChatInput.test.ts:
- onPaste -> onImagePaste
Open in Gerrit

Related details

Attention is currently required from:
  • Samiya Caur
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: devtools/devtools-frontend
    Gerrit-Branch: main
    Gerrit-Change-Id: I2ce04b56a3114507d3728aed2429f98f6a2a1db9
    Gerrit-Change-Number: 7278223
    Gerrit-PatchSet: 2
    Gerrit-Owner: Emir D <emr...@gmail.com>
    Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
    Gerrit-Reviewer: Samiya Caur <sam...@chromium.org>
    Gerrit-Attention: Samiya Caur <sam...@chromium.org>
    Gerrit-Comment-Date: Mon, 22 Dec 2025 15:53:45 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Samiya Caur <sam...@chromium.org>
    unsatisfied_requirement
    open
    diffy

    Samiya Caur (Gerrit)

    unread,
    Dec 23, 2025, 4:13:31 AM (3 days ago) Dec 23
    to Emir D, Ergün Erdoğmuş, devtools-rev...@chromium.org
    Attention needed from Emir D

    Samiya Caur voted

    Code-Review+1
    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Emir D
    Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: devtools/devtools-frontend
    Gerrit-Branch: main
    Gerrit-Change-Id: I2ce04b56a3114507d3728aed2429f98f6a2a1db9
    Gerrit-Change-Number: 7278223
    Gerrit-PatchSet: 2
    Gerrit-Owner: Emir D <emr...@gmail.com>
    Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
    Gerrit-Reviewer: Samiya Caur <sam...@chromium.org>
    Gerrit-Attention: Emir D <emr...@gmail.com>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 09:13:27 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Ergün Erdoğmuş (Gerrit)

    unread,
    Dec 23, 2025, 5:53:58 AM (3 days ago) Dec 23
    to Emir D, Devtools-frontend LUCI CQ, Samiya Caur, devtools-rev...@chromium.org
    Attention needed from Emir D and Samiya Caur

    Ergün Erdoğmuş added 5 comments

    Patchset-level comments
    File-level comment, Patchset 2 (Latest):
    Ergün Erdoğmuş . resolved

    LGTM % some comments, thanks!

    File front_end/panels/ai_assistance/components/ChatInput.test.ts
    Line 172, Patchset 2 (Latest): const dataTransferItem = {
    Ergün Erdoğmuş . unresolved

    We can directly construct `DataTransfer` object here and give it to the `ClipboardEvent` as `clipboardData` instead of doing type assertions through `unknown`.

    Something like this should work out:
    ```
    const file = new File(['test'], 'pasted_image.png', {type: 'image/png'});
    const dataTransfer = new DataTransfer();
    dataTransfer.items.add(file);
          const clipboardEvent = new ClipboardEvent('paste', {
    clipboardData: dataTransfer,
    });
    ```
    Line 189, Patchset 2 (Latest): data: 'dGVzdA==',
    Ergün Erdoğmuş . unresolved

    (super nit): Let's use `data: btoa('test')` to provide a link between the used `File` and the test assertion.

    Line 194, Patchset 2 (Latest): fileReaderStub.restore();
    Ergün Erdoğmuş . unresolved

    We have an `afterEach` that restores all the stubbed methods, we don't need to call this specifically; feel free to remove this call :)

    File front_end/panels/ai_assistance/components/ChatInput.ts
    Line 563, Patchset 2 (Latest): for (const item of items) {
    Ergün Erdoğmuş . unresolved

    (nit): We can avoid the imperative loop here. When we iterate with `continue`, we force the reader to parse the control flow to understand the goal.

    If we use `Array.from(items).find(...)`, the code becomes "declarative". It describes what we want (an image item) rather than how to loop through the list.

    ===

    I have also realized that we can use the `files` property from `clipboardData` too, so we won't need calling `getAsFile()` if we find the files directly from there. Let's use that to find the image file.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Emir D
    • Samiya Caur
    Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: devtools/devtools-frontend
      Gerrit-Branch: main
      Gerrit-Change-Id: I2ce04b56a3114507d3728aed2429f98f6a2a1db9
      Gerrit-Change-Number: 7278223
      Gerrit-PatchSet: 2
      Gerrit-Owner: Emir D <emr...@gmail.com>
      Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
      Gerrit-Reviewer: Samiya Caur <sam...@chromium.org>
      Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
      Gerrit-Attention: Emir D <emr...@gmail.com>
      Gerrit-Attention: Samiya Caur <sam...@chromium.org>
      Gerrit-Comment-Date: Tue, 23 Dec 2025 10:53:53 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Emir D (Gerrit)

      unread,
      Dec 23, 2025, 12:14:14 PM (3 days ago) Dec 23
      to Devtools-frontend LUCI CQ, Samiya Caur, Ergün Erdoğmuş, devtools-rev...@chromium.org
      Attention needed from Ergün Erdoğmuş and Samiya Caur

      Emir D added 5 comments

      Patchset-level comments
      File-level comment, Patchset 3 (Latest):
      Emir D . resolved

      The patchset 3 has been published due to last comments.

      File front_end/panels/ai_assistance/components/ChatInput.test.ts
      Line 172, Patchset 2: const dataTransferItem = {
      Ergün Erdoğmuş . resolved

      We can directly construct `DataTransfer` object here and give it to the `ClipboardEvent` as `clipboardData` instead of doing type assertions through `unknown`.

      Something like this should work out:
      ```
      const file = new File(['test'], 'pasted_image.png', {type: 'image/png'});
      const dataTransfer = new DataTransfer();
      dataTransfer.items.add(file);
            const clipboardEvent = new ClipboardEvent('paste', {
      clipboardData: dataTransfer,
      });
      ```
      Emir D

      Related file has been edited. Now we are constructing DataTransfer here. We are not now using 'unknown' case.

      Line 189, Patchset 2: data: 'dGVzdA==',
      Ergün Erdoğmuş . resolved

      (super nit): Let's use `data: btoa('test')` to provide a link between the used `File` and the test assertion.

      Emir D

      I edited the test data with btoa() method to provide a link between the used File and the test assertion.

      Line 194, Patchset 2: fileReaderStub.restore();
      Ergün Erdoğmuş . resolved

      We have an `afterEach` that restores all the stubbed methods, we don't need to call this specifically; feel free to remove this call :)

      Emir D

      I removed this call. I'm trying to get used to Google culture :)

      File front_end/panels/ai_assistance/components/ChatInput.ts
      Line 563, Patchset 2: for (const item of items) {
      Ergün Erdoğmuş . resolved

      (nit): We can avoid the imperative loop here. When we iterate with `continue`, we force the reader to parse the control flow to understand the goal.

      If we use `Array.from(items).find(...)`, the code becomes "declarative". It describes what we want (an image item) rather than how to loop through the list.

      ===

      I have also realized that we can use the `files` property from `clipboardData` too, so we won't need calling `getAsFile()` if we find the files directly from there. Let's use that to find the image file.

      Emir D

      I edited the ChatView.ts file and now we are using Array.from() method to check files in clipboard. Also now, we are getting the image from files property which in clipboardData.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Ergün Erdoğmuş
      • Samiya Caur
      Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: devtools/devtools-frontend
        Gerrit-Branch: main
        Gerrit-Change-Id: I2ce04b56a3114507d3728aed2429f98f6a2a1db9
        Gerrit-Change-Number: 7278223
        Gerrit-PatchSet: 3
        Gerrit-Owner: Emir D <emr...@gmail.com>
        Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
        Gerrit-Reviewer: Samiya Caur <sam...@chromium.org>
        Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
        Gerrit-Attention: Ergün Erdoğmuş <erg...@chromium.org>
        Gerrit-Attention: Samiya Caur <sam...@chromium.org>
        Gerrit-Comment-Date: Tue, 23 Dec 2025 17:14:10 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Ergün Erdoğmuş <erg...@chromium.org>
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Ergün Erdoğmuş (Gerrit)

        unread,
        Dec 24, 2025, 5:34:22 AM (2 days ago) Dec 24
        to Emir D, Devtools-frontend LUCI CQ, Samiya Caur, devtools-rev...@chromium.org
        Attention needed from Emir D and Samiya Caur

        Ergün Erdoğmuş voted Code-Review+1

        Code-Review+1
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Emir D
        • Samiya Caur
        Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: devtools/devtools-frontend
        Gerrit-Branch: main
        Gerrit-Change-Id: I2ce04b56a3114507d3728aed2429f98f6a2a1db9
        Gerrit-Change-Number: 7278223
        Gerrit-PatchSet: 4
        Gerrit-Owner: Emir D <emr...@gmail.com>
        Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
        Gerrit-Reviewer: Samiya Caur <sam...@chromium.org>
        Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
        Gerrit-Attention: Emir D <emr...@gmail.com>
        Gerrit-Attention: Samiya Caur <sam...@chromium.org>
        Gerrit-Comment-Date: Wed, 24 Dec 2025 10:34:18 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages