|
116 | 116 |
|
117 | 117 | // Force reload iframe if it doesn't load within 5 seconds |
118 | 118 | const timeout = setTimeout(() => { |
119 | | - try { |
120 | | - // Check if iframe loaded properly |
121 | | - if (!iframe.contentWindow || !iframe.contentDocument || |
122 | | - !iframe.contentDocument.body || |
123 | | - iframe.contentDocument.body.innerHTML === "") { |
124 | | - console.log("Payment form might be blocked - showing fallback"); |
125 | | - fallbackContainer.style.display = "block"; |
126 | | - iframe.style.display = "none"; |
127 | | - } |
128 | | - } catch (e) { |
129 | | - // If we get a security error when trying to access iframe contents, |
130 | | - // that indicates a cross-origin issue |
131 | | - console.log("Security error accessing iframe - likely blocked by browser", e); |
| 119 | + // We can't reliably check cross-origin iframe content |
| 120 | + // Just ensure the iframe is visible and working |
| 121 | + if (!iframe.style.height || iframe.style.height === "0px") { |
| 122 | + console.log("Payment form might be blocked - showing fallback"); |
132 | 123 | fallbackContainer.style.display = "block"; |
133 | 124 | iframe.style.display = "none"; |
134 | 125 | } |
|
138 | 129 | iframe.onload = () => { |
139 | 130 | clearTimeout(timeout); |
140 | 131 | |
141 | | - // Additional check after load to verify content is accessible |
142 | | - try { |
143 | | - // If we can access the iframe's location, it loaded successfully |
144 | | - const testAccess = iframe.contentWindow.location.href; |
145 | | - fallbackContainer.style.display = "none"; |
146 | | - } catch (e) { |
147 | | - // If we get a security error, the content might have loaded but is |
148 | | - // not accessible due to cross-origin restrictions |
149 | | - console.log("Iframe loaded but content might be restricted", e); |
150 | | - |
151 | | - // Set a longer timeout to give time for the actual form to render |
152 | | - // before showing fallback message |
153 | | - setTimeout(() => { |
154 | | - try { |
155 | | - // One final check before showing fallback |
156 | | - if (!iframe.contentWindow.document.body.innerHTML) { |
157 | | - fallbackContainer.style.display = "block"; |
158 | | - iframe.style.display = "none"; |
159 | | - } |
160 | | - } catch (e) { |
161 | | - fallbackContainer.style.display = "block"; |
162 | | - iframe.style.display = "none"; |
163 | | - } |
164 | | - }, 1000); |
| 132 | + // We should not try to access iframe.contentWindow.location.href |
| 133 | + // as it will cause cross-origin errors in most browsers |
| 134 | + console.log("Iframe loaded successfully"); |
| 135 | + |
| 136 | + // Set a reasonable height for the iframe initially |
| 137 | + if (!iframe.style.height || iframe.style.height === "0px") { |
| 138 | + iframe.style.height = "600px"; |
165 | 139 | } |
| 140 | + |
| 141 | + // Hide fallback by default - we assume the iframe loaded |
| 142 | + fallbackContainer.style.display = "none"; |
166 | 143 | }; |
167 | 144 | } |
168 | 145 |
|
|
0 commit comments