Devtools picture-in-picture: window.open reuses a cross-origin popup named TSQD-Devtools-Panel (SecurityError) #12700
Describe the bug#
When the Query devtools switch to picture-in-picture, PiPProvider opens the popup with window.open('', 'TSQD-Devtools-Panel', ...) and then writes to pip.document. The window name is fixed. If a window with that name already exists in the same browsing context group but belongs to another origin (for example the devtools popup of a second app on another localhost port, opened from the same tab), window.open returns that existing cross-origin window, and the first pip.document access throws:
SecurityError: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "http://localhost:3001" from accessing a cross-origin frame.
Picture-in-picture does not open. When pip_open is persisted as "true", the same error is thrown on every page load by the effect that reopens the popup, where it surfaces as an unhandled rejection (Uncaught (in promise)) under ReactQueryDevtools.
Your minimal, reproducible example#
No hosted sandbox, because it needs two apps on two origins in one tab. Any two apps that render <ReactQueryDevtools /> reproduce it, for example two Vite dev servers on localhost:3001 and localhost:3002.
Steps to reproduce#
- Run two apps that each render
<ReactQueryDevtools />: app A onhttp://localhost:3002, app B onhttp://localhost:3001. - In one tab, open app A, open the devtools and click "Open in picture-in-picture mode". A popup named
TSQD-Devtools-Panelopens. Leave it open. - In the same tab, navigate to app B, open the devtools and click "Open in picture-in-picture mode".
- The console shows
Uncaught SecurityError: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "http://localhost:3001" from accessing a cross-origin frame.and no popup opens.
On load: with TanstackQueryDevtools.pip_open set to "true" in both origins' localStorage (picture-in-picture left on in both apps), moving the tab from one app to the other logs the same SecurityError as an unhandled rejection on every load.
Expected behavior#
Each app's devtools open (or reuse) their own picture-in-picture popup. A popup from another origin that shares the window name is never touched.
How often does this bug happen?#
Every time
Platform#
- OS: macOS
- Browser: Chrome 158
Tanstack Query adapter#
react-query
TanStack Query version#
5.107.1 (@tanstack/react-query-devtools and @tanstack/query-devtools). main still has the same code: https://github.com/TanStack/query/blob/f7abc938a8a7fe801d78f4cfdb98d65422f276b2/packages/query-devtools/src/contexts/PiPContext.tsx#L63-L77
TypeScript version#
Not involved (runtime behavior)
Additional context#
Two possible fixes:
- give the popup an origin-specific name, for example
`TSQD-Devtools-Panel-${location.origin}`, so two origins never share one; - or check that the returned window is accessible before using it (a
try/catcharound the firstpip.documentread) and, when it is not, open a uniquely named popup or throwPipOpenError, so the existing handler resetspip_openinstead of the error escaping.
tanstack-source added labelsbug
imadization(GitHub profile, opens in a new tab) linked this to #12702
mgarcia-improving(GitHub profile, opens in a new tab) linked this to #12711
Sign in to join this conversation.
I'll work on this.