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

Function requestPipWindow

packages/devtools/src/context/pip-context.tsx:44–131  ·  view source on GitHub ↗
(settings: string)

Source from the content-addressed store, hash-verified

42 }
43
44 // Open new pipWindow
45 const requestPipWindow = (settings: string) => {
46 // We don't want to allow multiple requests.
47 if (pipWindow() != null) {
48 return
49 }
50
51 const pip = window.open('', 'TSDT-Devtools-Panel', `${settings},popup`)
52
53 if (!pip) {
54 throw new Error(
55 'Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.',
56 )
57 }
58
59 if (import.meta.hot && typeof import.meta.hot.on === 'function') {
60 import.meta.hot.on('vite:beforeUpdate', () => {
61 localStorage.setItem('pip_open', 'false')
62 closePipWindow()
63 })
64 }
65 window.addEventListener('beforeunload', () => {
66 localStorage.setItem('pip_open', 'false')
67 closePipWindow()
68 })
69 // Remove existing styles
70 pip.document.head.innerHTML = ''
71 // Remove existing body
72 pip.document.body.innerHTML = ''
73
74 pip.document.title = 'TanStack Devtools'
75 pip.document.body.style.margin = '0'
76
77 // Detect when window is closed by user
78 pip.addEventListener('pagehide', () => {
79 localStorage.setItem('pip_open', 'false')
80 closePipWindow()
81 })
82
83 // It is important to copy all parent window styles. Otherwise, there would be no CSS available at all
84 // https://developer.chrome.com/docs/web-platform/document-picture-in-picture/#copy-style-sheets-to-the-picture-in-picture-window
85 ;[...document.styleSheets].forEach((styleSheet) => {
86 try {
87 const cssRules = [...styleSheet.cssRules]
88 .map((rule) => rule.cssText)
89 .join('')
90 const style = document.createElement('style')
91 const style_node = styleSheet.ownerNode
92 let style_id = ''
93
94 if (style_node && 'id' in style_node) {
95 style_id = style_node.id
96 }
97
98 if (style_id) {
99 style.setAttribute('id', style_id)
100 }
101 style.textContent = cssRules

Callers

nothing calls this directly

Calls 2

closePipWindowFunction · 0.85
onMethod · 0.45

Tested by

no test coverage detected