Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoStartBrowser starts the wrong url #580

Closed
maxschmi opened this issue Jan 30, 2025 · 10 comments · Fixed by #646 · May be fixed by #581
Closed

autoStartBrowser starts the wrong url #580

maxschmi opened this issue Jan 30, 2025 · 10 comments · Fixed by #646 · May be fixed by #581
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@maxschmi
Copy link

context

I have a django app and customized my djangoadmin runserver command to also start a vite debugging server for my frontend.
Therefor when starting my debugging server I get two url's in my stdout of djangoadmin runserver.

Problem

When I want to use the autoStartBrowser:true option of my debugpy setup to automatically start a browser, it starts the wrong URL. So my vite server-URL is started in the Browser instead of my django webpage.

Sugested solution

Add an additional setting to customize the startup URL. E.g.:

"autoStartBrowser": true,
"autoStartBrowserURL": "http://localhost:8000",
@eleanorjboyd
Copy link
Member

Hi! Sent some messages in the PR thread but better news is I think we already have a solution that may work for you! There is a option to configure serverReadyAction which is built-in and works for all debug configs. This is the doc about it: https://code.visualstudio.com/Docs/editor/debugging#_automatically-open-a-uri-when-debugging-a-server-program. I gave it a try on my side and it seemed to do the correct thing so let me know if it works for you! Thanks

@eleanorjboyd eleanorjboyd added the info-needed Issue requires more information from poster label Feb 13, 2025
@maxschmi
Copy link
Author

Hmm yeah that is a valid alternative to work with. So basically this sets the serverReadyAction manually, whereas the proposed autoStartBrowserURL would do this automatically

@eleanorjboyd
Copy link
Member

looping in @connor4312 since he is the expert of this setting, wondering if he has any advice to make it automatic or better for your use case

@connor4312
Copy link
Member

connor4312 commented Feb 14, 2025

Yea. I don't know how the Python implementation of autoStartBrowserURL works, but serverReadyAction might work for you. It's quite manual and explicit but it should be reliable.

maybe serverReadyAction should support AI power in the future to figure out the URL from program output magically, but we aren't there right now :)

@eleanorjboyd
Copy link
Member

The python implementation you mean from debugpy or from the debugger extension? I looked and the debugger passes on the arguments without editing

@eleanorjboyd
Copy link
Member

looping in @rchiodo as well

@rchiodo
Copy link
Contributor

rchiodo commented Feb 14, 2025

AFAIK, debugpy doesn't handle the autoStartBrowser configuration. The extension does here:

if (debugConfiguration.autoStartBrowser && (debugConfiguration.django || isFlask)) {
debugConfiguration.serverReadyAction = {
pattern: '.*(https?:\\/\\/\\S+:[0-9]+\\/?).*',
uriFormat: '%s',
action: 'openExternally',
};
}
if (

Not sure if that means the serverReadyAction wouldn't work because there would be duplicates?

@connor4312
Copy link
Member

Yea, looks like that would overwrite serverReadyAction if present

@eleanorjboyd
Copy link
Member

Hi! I have put in a fix for this so it doesn't overwrite the setting if present, @maxschmi if you are able to get the most recent pre-release version of the vscode python debugger (latest released should say this morning) and give it a try to let me know if that works that would be great, thanks!

@maxschmi
Copy link
Author

maxschmi commented Mar 5, 2025

Hey @eleanorjboyd

I'm not so sure what to test. I did install the latest pre-release, but the "autoStartBrowserURL" option is not available. But I guess you decided against the pattern option.

If I have :

"name": "Django server",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder:python}\\manage.py",
"args": [
	"runserver",
	"localhost:8000"
],
"django": true,
"autoStartBrowser": true,
"serverReadyAction": {
	"pattern": "Starting development server at http://localhost:([0-9]+)/",
	"action": "openExternally",
	"uriFormat": "http://localhost:%s"
}

The "serverReadyAction" is executed, but unfortunatly is not detecting or not using the correct port, but instead uses 3000 as a port.
As far as I see, the "autoStartBrowser" option is more less ignored. Is that the excpected outcome?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
4 participants