Closing a tab whose layout has unsaved changes opens a TradingView confirmation window — "Close tab? There are unsaved changes on your chart layout. You will lose them if you close the tab." with Save and close / Close without saving. The dialog blocks the close, and tab_close then reports:
The close was clicked but the tab count did not drop (2 -> 2)
The message is accurate and completely misleading: it reads like a selector or window-scoping problem. I spent most of a session concluding tab_close could not reach tabs in a second Desktop window before finding the dialog.
Why it is invisible to the current code
The dialog is its own CDP page target. It is not in the chart page's DOM ([role=dialog], [data-name*=dialog] and friends find nothing) and it is not in the tab-strip shell that _withShell drives. Enumerating /json/list and reading document.body.innerText on each non-chart page target finds it immediately:
body: "Close tab? There are unsaved changes on your chart layout. You will lose them if you close the tab. Save and close Close without saving"
buttons: ["Save and close", "Close without saving", "close-dialog-window"]
Reproduce
tab_new a layout, change the symbol so the layout is dirty.
tab_close.
Suggested fix
Detect it and say so, rather than reporting a count mismatch. Even without deciding for the user, an error like
the tab has unsaved layout changes and TradingView is asking whether to save; answer the dialog, or pass discard_unsaved: true
turns a dead end into a one-step recovery. An opt-in discard_unsaved that clicks Close without saving would make disposable scratch tabs practical — that is the use case that runs into this every time, since a scratch tab is dirty by construction.
Clicking the button from the dialog target works:
[...document.querySelectorAll('button,[role=button]')]
.find(b => b.textContent.trim() === 'Close without saving').click()
Verified on 2.3.0 / Desktop 3.3.0 / macOS. Whatever the default, it should never be Save and close without being asked.
Closing a tab whose layout has unsaved changes opens a TradingView confirmation window — "Close tab? There are unsaved changes on your chart layout. You will lose them if you close the tab." with Save and close / Close without saving. The dialog blocks the close, and
tab_closethen reports:The message is accurate and completely misleading: it reads like a selector or window-scoping problem. I spent most of a session concluding
tab_closecould not reach tabs in a second Desktop window before finding the dialog.Why it is invisible to the current code
The dialog is its own CDP page target. It is not in the chart page's DOM (
[role=dialog],[data-name*=dialog]and friends find nothing) and it is not in the tab-strip shell that_withShelldrives. Enumerating/json/listand readingdocument.body.innerTexton each non-chart page target finds it immediately:Reproduce
tab_newa layout, change the symbol so the layout is dirty.tab_close.Suggested fix
Detect it and say so, rather than reporting a count mismatch. Even without deciding for the user, an error like
turns a dead end into a one-step recovery. An opt-in
discard_unsavedthat clicks Close without saving would make disposable scratch tabs practical — that is the use case that runs into this every time, since a scratch tab is dirty by construction.Clicking the button from the dialog target works:
Verified on 2.3.0 / Desktop 3.3.0 / macOS. Whatever the default, it should never be Save and close without being asked.