Skip to content

Conversation

sven-ola
Copy link

@sven-ola sven-ola commented Sep 1, 2025

Use postMessage(data,url) to notify parent window on ttyd socket close

@tsl0922
Copy link
Owner

tsl0922 commented Sep 2, 2025

Do you have any thoughts to make some common APIs for the postmessage interface?

cc @itadventurer for #1468

@itadventurer
Copy link

That would be cool. I have just implemented the most important (for me) in the PR but having the most relevant APIs available over postmessage would be cool.

@sven-ola
Copy link
Author

sven-ola commented Sep 4, 2025

That would be cool. I have just implemented the most important (for me) in the PR but having the most relevant APIs available over postmessage would be cool.

Maybe it is better allow integrating the ttyd window in a website instead of a new cross-origin-postmessage() API. Or do it vice versa: an option to forward unknown GETs and POSTs to some other port on same machine as it's done with stunnel other reverse proxies.

@itadventurer
Copy link

How would you do that? The thing is, if ttyd is hosted on another (sub)domain and you include it in an iframe it seems quite hard to access it somehow from the parent window. Thats why the postmessage api is quite nice i think.
But I am open to other solutions to integrate ttyd in an iframe and send commands to it :)

@sven-ola
Copy link
Author

sven-ola commented Sep 4, 2025

Ttyd is started on 8080 and forwards unknown GET and POST to localhost:80. Client browser starts with http://page.html:8080. Ttyd does not have page.html, forwards to busybox httpd on port 80, which in turn outputs page.html which in turn has <iframe src="index.html">. Browser now grabs http://index.html:8080. Ttyd serves this well known page with default content (html.h). Browser now has two pages from same origin. Thus same-origin policy applies and any Javascript in page.html can do whatever is necessary, for example add some events to ttyd-close-socket-javascript.

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.

3 participants