catch Simple Browser tab close event #2450
Unanswered
Zelfior
asked this question in
Extension Development QnA
Replies: 1 comment
-
Hi @Zelfior - I don't know an answer off the top of my head but I gave Copilot a shot at it and this is the code it came up with: const vscode = require('vscode');
let terminal;
let panel;
function activate(context) {
// Create the terminal and start the server
terminal = vscode.window.createTerminal("My Server");
terminal.sendText("python -m http.server"); // Example command, replace with yours
terminal.show();
// Open the webpage
panel = vscode.window.createWebviewPanel(
'myWebview',
'Server Page',
vscode.ViewColumn.One,
{}
);
panel.webview.html = `<html><body><h1>Server Running</h1></body></html>`;
// Close terminal when webview is closed
panel.onDidDispose(() => {
terminal.dispose();
});
context.subscriptions.push(panel);
}
function deactivate() {
if (terminal) {
terminal.dispose();
}
}
module.exports = {
activate,
deactivate
}; Let me know if it works! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
i am developing an extension where i open a server from a python command in a terminal, and open show the server webpage using a simplebrowser.show. How can i get to close the terminal when the browser tab is closed?
I expect something like this, but i don't know where to get the "SOMETHING".
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions