Generate code in Console and Sources

Use Gemini to generate code in the Console and Sources panels.

From Chrome 147, this feature is available for all text-based resources for a web page. The priority language for code generation is JavaScript.

Code generation feature in the Console and Sources panels.

Availability

To use any of the available AI features in DevTools, make sure that you:

  • Are at least 18 years old and are in one of the supported locations.
  • Are using the latest version of Chrome.
  • Are signed into Chrome with your Google Account.
  • Have English (US) selected in Settings > Preferences > Appearance > Language in DevTools.
  • Have enabled Settings > AI Innovations in DevTools.

Enable code generation

To enable code generation specifically, go to DevTools > Settings > AI innovations and turn on Code suggestions.

Code suggestion feature toggle in Settings - AI innovations.

To enable code generation right from the Console or Sources panel:

  1. While editing source files or typing in the Console, press Command + i on Mac or Control + i. In this shortcut, i is lowercase.

    Turning on code suggestions in Sources and Console with a shortcut.

  2. Read through Things to consider in the dialog window and click Got it.

    'Things to consider' dialog window.

Generate code

To generate code in the Console or Sources panel:

  1. In a code comment, type your prompt, for example: // Loop to check all img elements for valid alt attributes.

    A prompt for code generation in a JavaScript comment.

  2. To start generating, press Command + i on Mac or Control + i. In this shortcut, i is lowercase.

  3. Wait for code generation to finish. It may take a few seconds.

  4. Press Tab or Enter to accept or Esc to reject the generated code block.

    Accepting or rejecting a generated code block.

See also