()
| 256 | const loadingLinkId = ++loadingLinkCounter; |
| 257 | |
| 258 | async function getRulesAsync(): Promise<CSSRuleList | null> { |
| 259 | let cssText: string; |
| 260 | let cssBasePath: string; |
| 261 | |
| 262 | if (element instanceof HTMLLinkElement) { |
| 263 | let [cssRules, accessError] = getRulesOrError(); |
| 264 | if (accessError) { |
| 265 | logWarn(accessError); |
| 266 | } |
| 267 | |
| 268 | if ( |
| 269 | (isSafari && !element.sheet) || |
| 270 | (!isSafari && !cssRules && !accessError) || |
| 271 | isStillLoadingError(accessError!) |
| 272 | ) { |
| 273 | try { |
| 274 | logInfo(`Linkelement ${loadingLinkId} is not loaded yet and thus will be await for`, element); |
| 275 | await linkLoading(element, loadingLinkId); |
| 276 | } catch (err) { |
| 277 | // NOTE: Some @import resources can fail, |
| 278 | // but the style sheet can still be valid. |
| 279 | // There's no way to get the actual error. |
| 280 | logWarn(err); |
| 281 | wasLoadingError = true; |
| 282 | } |
| 283 | if (cancelAsyncOperations) { |
| 284 | return null; |
| 285 | } |
| 286 | |
| 287 | [cssRules, accessError] = getRulesOrError(); |
| 288 | if (accessError) { |
| 289 | // CORS error, cssRules are not accessible |
| 290 | // for cross-origin resources |
| 291 | logWarn(accessError); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | if (cssRules) { |
| 296 | if (!hasImports(cssRules, false)) { |
| 297 | return cssRules; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | try { |
| 302 | cssText = await loadText(element.href); |
| 303 | } catch (err) { |
| 304 | logWarn(err); |
| 305 | cssText = ''; |
| 306 | } |
| 307 | cssBasePath = getCSSBaseBath(element.href); |
| 308 | if (cancelAsyncOperations) { |
| 309 | return null; |
| 310 | } |
| 311 | } else if (containsCSSImport()) { |
| 312 | cssText = element.textContent!.trim(); |
| 313 | cssBasePath = getCSSBaseBath(location.href); |
| 314 | } else { |
| 315 | return null; |
no test coverage detected