From 5036d9f528ea35e6a3fed6bd120153405e33cb21 Mon Sep 17 00:00:00 2001 From: Francois Lopitaux Date: Mon, 19 Oct 2026 10:50:05 -0700 Subject: [PATCH 01/10] Let charts render by relaxing frame-ancestors on nested frames ThoughtSpot draws charts in an iframe on its own chart host, which sends `frame-ancestors *`. In CSP, `*` only matches network schemes, so the file:// page the renderer runs on is never an allowed ancestor and Chromium blocks the frame. The embed then shows "Cannot display the chart", while the same answer renders fine in a browser. For subframes on other origins, drop only frame-ancestors and X-Frame-Options and keep the rest of their policy. Header names are now matched case-insensitively instead of by listing spellings. Co-Authored-By: Claude Opus 5.5 --- src/main/main.js | 57 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/src/main/main.js b/src/main/main.js index 8b0554a..b79dee7 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -48,6 +48,42 @@ function rememberBounds() { }, 400); } +// ---------- Response header rewriting ---------- + +const CSP_HEADERS = [ + 'x-frame-options', + 'content-security-policy', + 'content-security-policy-report-only', +]; + +// Header names arrive in whatever case the server sent, so every lookup here is +// case-insensitive rather than guessing at spellings. +function withoutHeaders(responseHeaders, names) { + const headers = { ...responseHeaders }; + for (const key of Object.keys(headers)) { + if (names.includes(key.toLowerCase())) delete headers[key]; + } + return headers; +} + +// Drop frame-ancestors from a CSP while leaving the directives that protect the +// framed page itself — script-src, connect-src and the rest — in force. +function withoutFrameAncestors(responseHeaders) { + const headers = withoutHeaders(responseHeaders, ['x-frame-options']); + for (const [key, value] of Object.entries(headers)) { + const name = key.toLowerCase(); + if (name !== 'content-security-policy' && name !== 'content-security-policy-report-only') continue; + const policies = (Array.isArray(value) ? value : [value]).map((policy) => ( + policy + .split(';') + .filter((directive) => directive.trim().split(/\s+/)[0].toLowerCase() !== 'frame-ancestors') + .join(';') + )); + headers[key] = policies; + } + return headers; +} + // ---------- Session hardening ---------- // Embedded content must never be able to spawn an unmanaged BrowserWindow — @@ -91,15 +127,20 @@ function configureSession() { // Strip framing and CSP restrictions so the embed iframe works. Scoped to the // configured ThoughtSpot origin so third-party requests (e.g. OIDC providers) // keep their security headers. + // + // Nested frames on other origins get a narrower treatment: only the rules that + // decide who may frame them are dropped, and the rest of their policy stands. + // ThoughtSpot renders charts in an iframe on its own chart host, which allows + // `frame-ancestors *` — and `*` matches network schemes only, so the file:// + // page this app runs on is not an allowed ancestor and Chromium blocks the + // frame. The embedded app then shows "Cannot display the chart". A browser + // never hits this because its page is served over https. defaultSession.webRequest.onHeadersReceived((details, callback) => { - if (!isSameOrigin(details.url, currentTsHost)) return callback({}); - const headers = { ...details.responseHeaders }; - delete headers['x-frame-options']; - delete headers['X-Frame-Options']; - delete headers['content-security-policy']; - delete headers['Content-Security-Policy']; - delete headers['content-security-policy-report-only']; - delete headers['Content-Security-Policy-Report-Only']; + const trusted = isSameOrigin(details.url, currentTsHost); + if (!trusted && details.resourceType !== 'subFrame') return callback({}); + const headers = trusted + ? withoutHeaders(details.responseHeaders, CSP_HEADERS) + : withoutFrameAncestors(details.responseHeaders); callback({ responseHeaders: headers }); }); } From fd964095a5a1c1c2e0deb35018130f39f69362c1 Mon Sep 17 00:00:00 2001 From: Francois Lopitaux Date: Mon, 19 Oct 2026 10:50:05 -0700 Subject: [PATCH 02/10] Stop the embed from loading twice on every launch The SDK's React wrapper deep-compares its listeners, and when any of them changes identity it destroys the iframe and builds a new one. The handler maps were rebuilt on every render, and mergeHandlers made new wrappers too, so once auth and Orgs settled the app threw away a half-loaded ThoughtSpot and started over. Each launch aborted 25-41 CDN requests. A later re-render would also wipe the conversation on screen. Memoize each hook's handler map and the merged result. The embed now loads once and nothing is aborted. Co-Authored-By: Claude Opus 5.5 --- src/renderer/App.jsx | 14 ++++++++++++-- src/renderer/useAnswerNotification.js | 9 +++++---- src/renderer/useConversationActivity.js | 6 ++++-- src/renderer/useEmbedErrors.js | 6 ++++-- src/renderer/useSpotterAnalytics.js | 9 +++++---- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/renderer/App.jsx b/src/renderer/App.jsx index 85d2c87..a8539c4 100644 --- a/src/renderer/App.jsx +++ b/src/renderer/App.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState, useCallback, useRef } from 'react'; +import React, { useEffect, useState, useCallback, useMemo, useRef } from 'react'; import { init, Action, AuthType, AuthStatus, logout, getSessionInfo } from '@thoughtspot/visual-embed-sdk'; import { SpotterEmbed, useEmbedRef } from '@thoughtspot/visual-embed-sdk/react'; import { useAnswerNotification } from './useAnswerNotification'; @@ -337,6 +337,16 @@ function SpotterPage({ tsHost, appVersion, onSignOut, onAuthLost }) { }); const hostLabel = getHostLabel(tsHost); + // The SDK's React wrapper deep-compares its listeners and, when any of them + // changes identity, destroys the iframe and builds a new one — reloading all + // of ThoughtSpot and dropping the conversation on screen. Merging inline gave + // fresh wrappers on every render, so the embed loaded twice on each launch as + // auth and Orgs settled. Every input map is memoized, so this one is too. + const embedHandlers = useMemo( + () => mergeHandlers(answerNotification, analytics, shareAnalytics, conversationHandlers, errorHandlers), + [answerNotification, analytics, shareAnalytics, conversationHandlers, errorHandlers], + ); + // Keep the analytics super property in step with the Org actually in view, // on first load as well as after a switch. const currentOrgName = orgs.find((org) => org.id === currentOrgId)?.name; @@ -416,7 +426,7 @@ function SpotterPage({ tsHost, appVersion, onSignOut, onAuthLost }) { spotterShareModalTitle: 'Share this conversation', spotterShareEmptySubtitle: 'Not shared with anyone yet', }} - {...mergeHandlers(answerNotification, analytics, shareAnalytics, conversationHandlers, errorHandlers)} + {...embedHandlers} spotterSidebarConfig={{ enablePastConversationsSidebar: true, spotterSidebarTitle: 'My Conversations', diff --git a/src/renderer/useAnswerNotification.js b/src/renderer/useAnswerNotification.js index 9f577e8..742e2b2 100644 --- a/src/renderer/useAnswerNotification.js +++ b/src/renderer/useAnswerNotification.js @@ -1,4 +1,4 @@ -import { useCallback, useRef } from 'react'; +import { useCallback, useMemo, useRef } from 'react'; // Tell the user an answer landed while they were away — the thing a desktop app // can do that a browser tab cannot. @@ -26,11 +26,12 @@ export function useAnswerNotification() { window.electronAPI?.notifyResponseComplete(); }, []); - // Spread straight onto . - return { + // Spread straight onto . Memoized because the embed rebuilds + // its iframe whenever a listener changes identity. + return useMemo(() => ({ onSpotterQueryTriggered: onStart, onSpotterResponseComplete: onDone, onSpotterData: onDone, onData: onDone, - }; + }), [onStart, onDone]); } diff --git a/src/renderer/useConversationActivity.js b/src/renderer/useConversationActivity.js index 7f2b1d5..c2768ed 100644 --- a/src/renderer/useConversationActivity.js +++ b/src/renderer/useConversationActivity.js @@ -1,4 +1,4 @@ -import { useCallback, useRef } from 'react'; +import { useCallback, useMemo, useRef } from 'react'; // Whether the user has asked anything in the conversation currently on screen. // Switching Org reloads the embed and discards it, so this decides whether that @@ -18,8 +18,10 @@ export function useConversationActivity() { const hasAsked = useCallback(() => asked.current, []); const reset = useCallback(() => { asked.current = false; }, []); + const handlers = useMemo(() => ({ onSpotterQueryTriggered: onStart }), [onStart]); + return { - handlers: { onSpotterQueryTriggered: onStart }, + handlers, hasAsked, reset, }; diff --git a/src/renderer/useEmbedErrors.js b/src/renderer/useEmbedErrors.js index 928691e..1b84c31 100644 --- a/src/renderer/useEmbedErrors.js +++ b/src/renderer/useEmbedErrors.js @@ -1,4 +1,4 @@ -import { useCallback, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { EmbedErrorSeverity } from '@thoughtspot/visual-embed-sdk'; import { track } from './analytics'; @@ -36,5 +36,7 @@ export function useEmbedErrors() { // on its own terms rather than inheriting the old one's error screen. const reset = useCallback(() => setFatal(false), []); - return { handlers: { onError }, fatal, reset }; + const handlers = useMemo(() => ({ onError }), [onError]); + + return { handlers, fatal, reset }; } diff --git a/src/renderer/useSpotterAnalytics.js b/src/renderer/useSpotterAnalytics.js index 039174c..1378dbc 100644 --- a/src/renderer/useSpotterAnalytics.js +++ b/src/renderer/useSpotterAnalytics.js @@ -1,4 +1,4 @@ -import { useCallback, useRef } from 'react'; +import { useCallback, useMemo, useRef } from 'react'; import { track } from './analytics'; // Spotter usage events, read from the same embed signals the answer notification @@ -24,11 +24,12 @@ export function useSpotterAnalytics() { track('Answer Completed', { duration_ms: durationMs, signal }); }, []); - // Spread straight onto . - return { + // Spread straight onto . Memoized because the embed rebuilds + // its iframe whenever a listener changes identity. + return useMemo(() => ({ onSpotterQueryTriggered: onStart, onSpotterResponseComplete: () => complete('SpotterResponseComplete'), onSpotterData: () => complete('SpotterData'), onData: () => complete('Data'), - }; + }), [onStart, complete]); } From 5500243ab162ca1ac4745df2ae6fbafeb0f4d7e7 Mon Sep 17 00:00:00 2001 From: Francois Lopitaux Date: Mon, 19 Oct 2026 10:50:05 -0700 Subject: [PATCH 03/10] Update the embed SDK to 1.53.1 and Electron to 44.9.0 Co-Authored-By: Claude Opus 5.5 --- package-lock.json | 16 ++++++++-------- package.json | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 74e9ece..6410329 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,12 +16,12 @@ "@babel/preset-env": "^7.24.0", "@babel/preset-react": "^7.23.0", "@fontsource/inter": "^5.2.8", - "@thoughtspot/visual-embed-sdk": "^1.52.0", + "@thoughtspot/visual-embed-sdk": "^1.53.1", "app-builder-bin": "^4.2.0", "babel-loader": "^9.1.3", "css-loader": "^6.10.0", "dotenv": "^17.4.2", - "electron": "^44.4.1", + "electron": "^44.9.0", "electron-builder": "^26.15.3", "eslint": "^9.39.5", "eslint-plugin-react": "^7.37.5", @@ -2591,9 +2591,9 @@ } }, "node_modules/@thoughtspot/visual-embed-sdk": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/@thoughtspot/visual-embed-sdk/-/visual-embed-sdk-1.52.0.tgz", - "integrity": "sha512-P1bEhZMBiCG6PnQv3ShSfxpn6EF9aJA4LYPWyWnCtUXpNviPc/AsAhCrMom0ayxsvBmgdP4YpAGAuIRHLmFSZw==", + "version": "1.53.1", + "resolved": "https://registry.npmjs.org/@thoughtspot/visual-embed-sdk/-/visual-embed-sdk-1.53.1.tgz", + "integrity": "sha512-iLrX9/LoM8TCLmflZyBPlXzSavJ4SAVQD/vCkt0xH+o+sDhL1YWxpLa5MwbWm1KMcM0EpdQWEM/tJxuvqtcMEA==", "dev": true, "license": "ThoughtSpot Development Tools End User License Agreement", "dependencies": { @@ -4752,9 +4752,9 @@ } }, "node_modules/electron": { - "version": "44.4.1", - "resolved": "https://registry.npmjs.org/electron/-/electron-44.4.1.tgz", - "integrity": "sha512-gXJarQ2Utfn8G6bp/IqLXvckOSCtrxPWjFqQaqm02Gf4zYn1aP+RN9PKimoLH/DMqjKLfBrNC4C4CviPv0cXnQ==", + "version": "44.9.0", + "resolved": "https://registry.npmjs.org/electron/-/electron-44.9.0.tgz", + "integrity": "sha512-boP8zA5OIoMGYe3uWP4IqB1VJNoEzdHYgcBaVYnd1DBv5TogwXkbM4yJGSfNmYCzalVQ5J3TAIbaKOY+ILTnyg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 01503a5..48c9047 100644 --- a/package.json +++ b/package.json @@ -48,12 +48,12 @@ "@babel/preset-env": "^7.24.0", "@babel/preset-react": "^7.23.0", "@fontsource/inter": "^5.2.8", - "@thoughtspot/visual-embed-sdk": "^1.52.0", + "@thoughtspot/visual-embed-sdk": "^1.53.1", "app-builder-bin": "^4.2.0", "babel-loader": "^9.1.3", "css-loader": "^6.10.0", "dotenv": "^17.4.2", - "electron": "^44.4.1", + "electron": "^44.9.0", "electron-builder": "^26.15.3", "eslint": "^9.39.5", "eslint-plugin-react": "^7.37.5", From b4abcccbbab0902ce08614f6705c802653a44afa Mon Sep 17 00:00:00 2001 From: Francois Lopitaux Date: Mon, 19 Oct 2026 11:00:35 -0700 Subject: [PATCH 04/10] Drop the unused playwright-core dependency Nothing in the app, its build or CI imports it. Co-Authored-By: Claude Opus 5.5 --- package-lock.json | 14 -------------- package.json | 1 - 2 files changed, 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6410329..fa4443f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,6 @@ "html-webpack-plugin": "^5.6.0", "iconv-corefoundation": "^1.1.7", "mixpanel-browser": "^2.82.0", - "playwright-core": "^1.60.0", "react": "^18.2.0", "react-dom": "^18.2.0", "style-loader": "^3.3.4", @@ -8314,19 +8313,6 @@ "url": "https://paulmillr.com/funding/" } }, - "node_modules/playwright-core": { - "version": "1.60.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz", - "integrity": "sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=18" - } - }, "node_modules/plist": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/plist/-/plist-3.1.0.tgz", diff --git a/package.json b/package.json index 48c9047..5210d3f 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "html-webpack-plugin": "^5.6.0", "iconv-corefoundation": "^1.1.7", "mixpanel-browser": "^2.82.0", - "playwright-core": "^1.60.0", "react": "^18.2.0", "react-dom": "^18.2.0", "style-loader": "^3.3.4", From 41c71c0444717d668d83aa413d6e0d48dae885d0 Mon Sep 17 00:00:00 2001 From: Francois Lopitaux Date: Mon, 19 Oct 2026 11:00:35 -0700 Subject: [PATCH 05/10] Let users pin conversations in the sidebar Native Spotter ships pinning on, but embeds have it off unless spotterChatPinConfig asks for it (26.10+). Older clusters ignore the setting. Co-Authored-By: Claude Opus 5.5 --- src/renderer/App.jsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/renderer/App.jsx b/src/renderer/App.jsx index a8539c4..e52359e 100644 --- a/src/renderer/App.jsx +++ b/src/renderer/App.jsx @@ -431,6 +431,9 @@ function SpotterPage({ tsHost, appVersion, onSignOut, onAuthLost }) { enablePastConversationsSidebar: true, spotterSidebarTitle: 'My Conversations', spotterSidebarDefaultExpanded: false, + // Native Spotter ships pinning on; embeds have it off unless + // asked (26.10+). Older clusters ignore it. + spotterChatPinConfig: { enabled: true }, }} // The sidebar footer's docs/"Best Practices" link points at the // ThoughtSpot help site, which has nowhere useful to go from a From fdf6dcae1b1dcf2b494a3e1069b8b149ee9d22fd Mon Sep 17 00:00:00 2001 From: Francois Lopitaux Date: Mon, 19 Oct 2026 11:00:35 -0700 Subject: [PATCH 06/10] Keep checking for updates while the app stays open The only check ran at launch, so a dock app left open for days sat on an old build. Check every six hours, and 30 seconds after wake, since a long sleep has most likely skipped one. Each version is announced once, so a dismissed banner does not keep coming back. Co-Authored-By: Claude Opus 5.5 --- src/main/main.js | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/main.js b/src/main/main.js index b79dee7..952fded 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow, Notification, dialog, session, ipcMain, shell, screen } = require('electron'); +const { app, BrowserWindow, Notification, dialog, session, ipcMain, shell, screen, powerMonitor } = require('electron'); const path = require('path'); const config = require('./config'); const orgs = require('./orgs'); @@ -420,7 +420,39 @@ ipcMain.handle('open-auth-window', async () => { const onUpdateReady = (info) => sendToRenderer('update-available', info); -ipcMain.handle('check-for-updates', () => updater.checkForUpdates(onUpdateReady)); +// The renderer checks once at launch, but a dock app stays open for days and +// would otherwise sit on an old build until it is quit. Keep checking in the +// background, and again shortly after wake, since a long sleep has most likely +// skipped a check. The delay gives the network time to come back first. +const UPDATE_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000; +const UPDATE_CHECK_AFTER_WAKE_MS = 30 * 1000; + +// Each version is announced once. A banner the user dismissed should not come +// back every few hours for the same release. +let announcedVersion = null; + +async function checkForUpdatesAndRemember() { + const info = await updater.checkForUpdates(onUpdateReady); + if (info?.version) announcedVersion = info.version; + return info; +} + +async function checkForUpdatesInBackground() { + const previous = announcedVersion; + const info = await checkForUpdatesAndRemember(); + if (info && info.version !== previous) sendToRenderer('update-available', info); +} + +function scheduleUpdateChecks() { + setInterval(checkForUpdatesInBackground, UPDATE_CHECK_INTERVAL_MS); + let wakeTimer = null; + powerMonitor.on('resume', () => { + clearTimeout(wakeTimer); + wakeTimer = setTimeout(checkForUpdatesInBackground, UPDATE_CHECK_AFTER_WAKE_MS); + }); +} + +ipcMain.handle('check-for-updates', () => checkForUpdatesAndRemember()); ipcMain.handle('install-update', () => updater.quitAndInstall()); ipcMain.handle('open-external', (_event, url) => { @@ -437,11 +469,13 @@ app.whenReady().then(() => { onSwitchInstance: () => sendToRenderer('menu-action', 'switch-instance'), onSignOut: () => sendToRenderer('menu-action', 'sign-out'), onCheckForUpdates: async () => { - const info = await updater.checkForUpdates(onUpdateReady); + // Asked for explicitly, so always answer — even with "up to date". + const info = await checkForUpdatesAndRemember(); sendToRenderer('update-available', info || { mode: 'current' }); }, }); createWindow(); + scheduleUpdateChecks(); }); app.on('window-all-closed', () => { From 490c0b633128dc0c31de8a0451e9baa7add941c1 Mon Sep 17 00:00:00 2001 From: Francois Lopitaux Date: Mon, 19 Oct 2026 11:00:35 -0700 Subject: [PATCH 07/10] Follow the macOS appearance with a dark theme The app's own screens were light only, while the embedded Spotter follows the system appearance, so dark-mode users got a white flash at launch and a mismatched frame. Add dark tokens for the app and the sign-in splash, and make the native window background follow the appearance too, since it shows through on resize and reload. Setting the embed's theme from the host (isDarkMode, HostEvent.UpdateTheme) needs ThoughtSpot 26.12, so the embed keeps following the system for now. Co-Authored-By: Claude Opus 5.5 --- src/main/auth-loading.html | 13 ++++++++++++- src/main/main.js | 19 ++++++++++++++----- src/renderer/styles.css | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/main/auth-loading.html b/src/main/auth-loading.html index ca73cd9..0f185b6 100644 --- a/src/main/auth-loading.html +++ b/src/main/auth-loading.html @@ -5,7 +5,7 @@ + mirror src/renderer/styles.css, dark set included, so the wait looks like part of the app. --> Signing in…