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