ChatGPT解决这个技术问题 Extra ChatGPT

Automatically open Chrome developer tools when new tab/new window is opened

I have HTML5 application which opens in a new window by clicking a link. I'm a bit tired of pressing Shift + I each time I want to logging network communication to launch Developer tools because I need it always. I was not able to find an option to keep Developer Tools always enabled on startup.

Is there any way to open Developer tools automatically when new window is opened in Chrome?

I would love to know this as well. Only way I've found is to edit the source like this guy did: [link]groups.google.com/forum/?fromgroups=#!topic/…
I've scoured pretty hard, and the closest thing I can find is the create a new Pane inside the dev tools, with a Chrome Extension.
Using SendKeys with Python, you can launch Chrome and send +^j to simulate Ctrl Shift J, but that would only work with a new instance; you'd have to get a bit more creative with selenium or something in order to navigate to a given page...
Yeah, I also saw this variant but it is not applicable when you what to open dev tools for each new tab opened.
Here's a guy who modified the source code to add this capability. It appears to be out of date now, but at least we know your request is possible.

L
Lahiru Jayaratne

On opening the developer tools, with the developer tools window in focus, press F1. This will open a settings page. Check the "Auto-open DevTools for popups".

This worked for me.

https://i.stack.imgur.com/dHH3a.png


This works and is exactly what the OP was asking, it should be marked as the right answer
Also doesn't work for me with WebStorm. The page opens but no dev tools.
This works, but the "Preserve Logs" option is always unchecked, and if the popup redirects it doesn't show previous network requests. Any ideas how to make it preserve logs by default?
This only works for a specific subset of cases, please see bugs.chromium.org/p/chromium/issues/detail?id=410958#c87. It's not a general solution.
Doesn't work when starting from VS Code with Chome debug extension.
D
Dan Pritts

UPDATE 2:

See this answer . - 2019-11-05

You can also now have it auto-open Developer Tools in Pop-ups if they were open where you opened them from. For example, if you do not have Dev Tools open and you get a popup, it won't open with Dev Tools. But if you Have Dev Tools Open and then you click something, the popup will have Dev-Tools Automatically opened.

UPDATE:

Time has changed, you can now use --auto-open-devtools-for-tabs as in this answer – Wouter Huysentruit May 18 at 11:08

OP:

I played around with the startup string for Chrome on execute, but couldn't get it to persist to new tabs. I also thought about a defined PATH method that you could invoke from prompt. This is possible with the SendKeys command, but again, only on a new instance. And DevTools doesn't persist to new tabs.

Browsing the Google Product Forums, there doesn't seem to be a built-in way to do this in Chrome. You'll have to use a keystroke solution or F12 as mentioned above.

I recommended it as a feature. I know I'm not the first either.


@Seanny123: fixed! If you want this as a feature, feel free to Star this Chromium bug: code.google.com/p/chromium/issues/detail?id=410958
@Chiperific, you said you was playing around the startup string for Chrome on execute, but could not get it to persist to new tabs. I need this behavior on startup for only one tab, however. Can you share the way you did it for one tab only?
Time has changed, you can now use --auto-open-devtools-for-tabs as in this answer
Please consider editing your answer. It is obsolete but still very visible in SO.
The full command for OS X is (quit any running Chrome process first): /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --auto-open-devtools-for-tabs
A
Ani Menon

There is a command line switch for this: --auto-open-devtools-for-tabs

So for the properties on Google Chrome, use something like this:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --auto-open-devtools-for-tabs

Here is a useful link: chromium-command-line-switches


This definitely works and should probably be marked as accepted answer now. Checked for chromium Version 50.0.2661.102 Ubuntu 15.10 (64-bit) and opened it like this chromium-browser --auto-open-devtools-for-tabs
This doesn't work on Windows 7 Version 51.0.2704.103 m
The full command for OS X is (quit any running Chrome process first): /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --auto-open-devtools-for-tabs
Didn't work on Version 59.0.3071.115 (Official Build) (64-bit)
I updated the command line arguments to this: --auto-open-devtools-for-tabs --user-data-dir=c:\temp\chrome. This essentially tells Chrome to use a separate directory just for debugging and did the trick for me
E
Erin Mills

On a Mac: Quit Chrome, then run the following command in a terminal window:

open -a "Google Chrome" --args --auto-open-devtools-for-tabs

To clarify: this opens Chrome with the auto-open-devtools-for-tabs flag set. Quitting Chrome and reopening it using the normal application shortcut will open Chrome without the flag set. If you want a shortcut to opening Chrome with this flag set without having to open a terminal window, you can create a workflow in Automator, add a "Run Shell Script" item, and paste in the above script. Saving the workflow as an application will create a clickable app. See this answer in another thread: stackoverflow.com/a/281455/1512790
A
Andrew Patterson

Under the Chrome DevTools settings you enable:

Under Network -> Preserve Log Under DevTools -> Auto-open DevTools for popups


The best answer IMO
good answer but explained for linux: Go to developer console. Go to the hamburger menu. click settings (or f1). in the network section check preserve log. in the devtools section check auto-open devtools for popups
On MacOS in Chrome 85 it is now under Settings -> Global section.
r
recvfrom

With the Developer Tools window visible, click the menu icon (the three vertical dots in the top right corner) and click Settings.

https://i.stack.imgur.com/zdvQM.png

Under Dev Tools, check the Auto-open DevTools for popups option

https://i.stack.imgur.com/ryYrA.png


Chrome Version 86 the setting is on the same place but named differently, so: Settings -> Preferences -> Global -> Auto-open DevTools for popups.
Y
Yehia

F12 is easier than Ctrl+Shift+I


If you are on Windows or Linux
to hit f12 on a macbook, or pro you have to do fn+f12 (bottom left extreme + top right extreme), which is not comfortable for most keyboard users
Works great on linux... Another reason to switch. Did it on a Mac Pro, it's not perfect, but still way better than Apple OS
v
vincedgy

If you use Visual Studio Code (vscode), using the very popular vscode chrome debug extension (https://github.com/Microsoft/vscode-chrome-debug) you can setup a launch configuration file launch.json and specify to open the developer tool during a debug session.

This the launch.json I use for my React projects :

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome against localhost",
      "url": "http://localhost:3000",
      "runtimeArgs": ["--auto-open-devtools-for-tabs"],
      "webRoot": "${workspaceRoot}/src"
    }
  ]
}

The important line is "runtimeArgs": ["--auto-open-devtools-for-tabs"],

From vscode you can now type F5, Chrome opens your app and the console tab as well.


r
randolfarevalo

Answer for 2021:

Open the Developer Tool (CTRL+SHIFT+I on Windows) Click the "Gear" icon. THe new Settings window will appear.

https://i.stack.imgur.com/8mvnU.png

"Auto-open DevTools for popups" is now under "Preferences" section.

https://i.stack.imgur.com/BC7uZ.png


R
Robin

Use --auto-open-devtools-for-tabs flag while running chrome from command line

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --auto-open-devtools-for-tabs

https://developers.google.com/web/tools/chrome-devtools/open#auto


thanks ,It works on my computer.The premise is that all corresponding browser processes must be shut down first.
G
George Griffin

I came here looking for a similar solution. I really wanted to see the chrome output for the pageload from a new tab. (a form submission in my case) The solution I actually used was to modify the form target attribute so that the form submission would occur in the current tab. I was able to capture the network request. Problem Solved!


R
Ron Rebennack

Anyone looking to do this inside Visual Studio, this Code Project article will help. Just add "--auto-open-devtools-for-tabs" in the arguments box. Works on 2017.


In case Code Project page goes away: you go to the Execute drop-down, select Browse With..., Add..., Program is something like: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe and Arguments: --auto-open-devtools-for-tabs -incognito (incognito being optional)
K
Korayem

Yep,there is a way you could do it

Right click->Inspect->sources(tab) Towards Your right there will be a "pause script execution button"

I hope it helps!Peace

P.S:This is for the first time.From the second time onwards the dev tool loads automatically


S
Suraj Rao

You can open dock view settings and adjust the window as you want. Screenshot attached.

https://i.stack.imgur.com/KXWzn.png


Hi and welcome to Stack Overflow. Sorry for the downvote, but I believe your answer is very far off the mark here.
B
Belloz

You can open Dev Tools (F12 in Chrome) in new window by clicking three, vertical dots on the right bottom corner, and choose Open as Separate Window.