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

Callers

nothing calls this directly

Calls 2

closePipWindowFunction · 0.85
onMethod · 0.45

Tested by

no test coverage detected