Skip to content

Open the webgl viewer at localhost rather than the machine's hostname - #734

Open
marklescroart wants to merge 1 commit into
mainfrom
webgl-localhost-url
Open

Open the webgl viewer at localhost rather than the machine's hostname#734
marklescroart wants to merge 1 commit into
mainfrom
webgl-localhost-url

Conversation

@marklescroart

Copy link
Copy Markdown
Contributor

Mark did this with Claude to resolve an annoyance that only came up on my Mac laptop (see below). FWIW, I am still not comfortable letting Claude push; I am still trying to understand as completely as I can what, exactly, I am allowing the Borg to take over.

Here's what Claude has to say about the fix:

show() built the viewer URL from socket.gethostname(), then handed it to webbrowser.open(). That browser runs on the same machine as the server, so the hostname buys nothing there, and on macOS it actively gets in the way: with scutil HostName unset, gethostname() returns the mDNS name ("mymac.local"), which resolves to a long list of addresses -- two link-local ones with no usable scope among them -- and reaches the server only if the application firewall lets the python process accept connections on a non-loopback interface. The auto-opened tab then fails for reasons that look nothing like a pycortex problem.

The webgl.domain_name config option cannot help, since it is appended to the hostname rather than replacing it.

Build both URLs instead. localhost is what gets opened and what is printed first, matching what headless.py already does; the hostname URL is still printed (and still shown in the IPython link) for handing to someone on another machine, so remote setups relying on domain_name keep working. The port line now comes with a full URL, which is what you need anyway when the browser does not open on its own.

... AFAICT this is all reasonable.

show() built the viewer URL from socket.gethostname(), then handed it to
webbrowser.open(). That browser runs on the same machine as the server, so
the hostname buys nothing there, and on macOS it actively gets in the way:
with scutil HostName unset, gethostname() returns the mDNS name
("mymac.local"), which resolves to a long list of addresses -- two
link-local ones with no usable scope among them -- and reaches the server
only if the application firewall lets the python process accept
connections on a non-loopback interface. The auto-opened tab then fails
for reasons that look nothing like a pycortex problem.

The webgl.domain_name config option cannot help, since it is appended to
the hostname rather than replacing it.

Build both URLs instead. localhost is what gets opened and what is printed
first, matching what headless.py already does; the hostname URL is still
printed (and still shown in the IPython link) for handing to someone on
another machine, so remote setups relying on domain_name keep working. The
port line now comes with a full URL, which is what you need anyway when
the browser does not open on its own.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant