* Get the injection script that should be added to the iframe * * This returns an HTML script tag that will load the picker when inserted * into the iframe document.
(baseUrl: string = '')
| 98 | * into the iframe document. |
| 99 | */ |
| 100 | static getInjectionScript(baseUrl: string = ''): string { |
| 101 | return ` |
| 102 | <script id="__pilot-picker-injector"> |
| 103 | (function() { |
| 104 | if (window.__pilotPickerInjected) { |
| 105 | console.log('[Pilot] Picker already injected'); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | window.__pilotPickerInjected = true; |
| 110 | |
| 111 | const script = document.createElement('script'); |
| 112 | script.src = '${baseUrl}/picker/react-component-picker.js'; |
| 113 | script.id = '__pilot-picker-script'; |
| 114 | |
| 115 | script.onload = function() { |
| 116 | console.log('[Pilot] React component picker loaded successfully'); |
| 117 | }; |
| 118 | |
| 119 | script.onerror = function(error) { |
| 120 | console.error('[Pilot] Failed to load picker script:', error); |
| 121 | window.parent.postMessage({ |
| 122 | type: 'picker-load-error', |
| 123 | error: 'Failed to load picker script' |
| 124 | }, '*'); |
| 125 | }; |
| 126 | |
| 127 | document.head.appendChild(script); |
| 128 | })(); |
| 129 | </script> |
| 130 | `; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Get the inline script content for direct injection |