MCPcopy Create free account
hub / github.com/TanStack/query / requestPipWindow

Function requestPipWindow

packages/query-devtools/src/contexts/PiPContext.tsx:57–142  ·  view source on GitHub ↗
(width: number, height: number)

Source from the content-addressed store, hash-verified

55
56 // Open new pipWindow
57 const requestPipWindow = (width: number, height: number) => {
58 // We don't want to allow multiple requests.
59 if (pipWindow() != null) {
60 return
61 }
62
63 const pip = window.open(
64 '',
65 'TSQD-Devtools-Panel',
66 `width=${width},height=${height},popup`,
67 )
68
69 if (!pip) {
70 throw new PipOpenError(
71 'Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.',
72 )
73 }
74
75 // Remove existing styles and body. `replaceChildren` instead of
76 // `innerHTML = ''`, which Trusted Types block.
77 pip.document.head.replaceChildren()
78 pip.document.body.replaceChildren()
79 // Clear Delegated Events
80 clearDelegatedEvents(pip.document)
81
82 pip.document.title = 'TanStack Query Devtools'
83 pip.document.body.style.margin = '0'
84
85 // Detect when window is closed by user
86 pip.addEventListener('pagehide', () => {
87 props.setLocalStore('pip_open', 'false')
88 setPipWindow(null)
89 })
90
91 // It is important to copy all parent window styles. Otherwise, there would be no CSS available at all
92 // https://developer.chrome.com/docs/web-platform/document-picture-in-picture/#copy-style-sheets-to-the-picture-in-picture-window
93 ;[
94 ...(useQueryDevtoolsContext().shadowDOMTarget || document).styleSheets,
95 ].forEach((styleSheet) => {
96 try {
97 const cssRules = [...styleSheet.cssRules]
98 .map((rule) => rule.cssText)
99 .join('')
100 const style = document.createElement('style')
101 const style_node = styleSheet.ownerNode
102 let style_id = ''
103
104 if (style_node && 'id' in style_node) {
105 style_id = style_node.id
106 }
107
108 if (style_id) {
109 style.setAttribute('id', style_id)
110 }
111 style.textContent = cssRules
112 pip.document.head.appendChild(style)
113 } catch (e) {
114 const link = document.createElement('link')

Callers 1

PiPProviderFunction · 0.85

Calls 2

useQueryDevtoolsContextFunction · 0.90
toStringMethod · 0.80

Tested by

no test coverage detected