@@ -175,7 +175,6 @@ function createKarmaMiddleware ( |
175 | 175 | common.setNoCacheHeaders(response) |
176 | 176 |
|
177 | 177 | const scriptTags = [] |
178 | | - const scriptUrls = [] |
179 | 178 | for (const file of files.included) { |
180 | 179 | let filePath = file.path |
181 | 180 | const fileType = file.type || path.extname(filePath).substring(1) |
@@ -192,8 +191,6 @@ function createKarmaMiddleware ( |
192 | 191 | } |
193 | 192 | } |
194 | 193 |
|
195 | | - scriptUrls.push(filePath) |
196 | | - |
197 | 194 | if (fileType === 'css') { |
198 | 195 | scriptTags.push(`<link type="text/css" href="${filePath}" rel="stylesheet">`) |
199 | 196 | } else if (fileType === 'dom') { |
@@ -207,6 +204,20 @@ function createKarmaMiddleware ( |
207 | 204 | } |
208 | 205 | } |
209 | 206 |
|
| 207 | + const scriptUrls = [] |
| 208 | + // For client_with_context, html elements are not added directly through an iframe. |
| 209 | + // Instead, scriptTags is stored to window.__karma__.scriptUrls first. Later, the |
| 210 | + // client will read window.__karma__.scriptUrls and dynamically add them to the DOM |
| 211 | + // using DOMParser. |
| 212 | + if (requestUrl === '/client_with_context.html') { |
| 213 | + for (const script of scriptTags) { |
| 214 | + scriptUrls.push( |
| 215 | + // Escape characters with special roles (tags) in HTML. Open angle brackets are parsed as tags |
| 216 | + // immediately, even if it is within double quotations in browsers |
| 217 | + script.replace(/</g, '\\x3C').replace(/>/g, '\\x3E')) |
| 218 | + } |
| 219 | + } |
| 220 | + |
210 | 221 | const mappings = data.includes('%MAPPINGS%') ? files.served.map((file) => { |
211 | 222 | const filePath = filePathToUrlPath(file.path, basePath, urlRoot, proxyPath) |
212 | 223 | .replace(/\\/g, '\\\\') // Windows paths contain backslashes and generate bad IDs if not escaped |
|