diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index ba42c04d6987..6a8ce3a55e2e 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1497,15 +1497,23 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) { rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), handler); NS_ENSURE_SUCCESS(rv, rv); - rv = channel->AsyncOpen(loader); - NS_ENSURE_SUCCESS(rv, rv); - auto key = PreloadHashKey::CreateAsScript( aRequest->mURI, aRequest->CORSMode(), aRequest->mKind, aRequest->ReferrerPolicy()); aRequest->NotifyOpen(&key, channel, mDocument, aRequest->IsLinkPreloadScript()); + rv = channel->AsyncOpen(loader); + + if (NS_FAILED(rv)) { + // Make sure to inform any tags about failure to load the + // resource. + aRequest->NotifyStart(channel); + aRequest->NotifyStop(rv); + } + + NS_ENSURE_SUCCESS(rv, rv); + if (aRequest->IsModuleRequest()) { // We successfully started fetching a module so put its URL in the module // map and mark it as fetching. @@ -1966,6 +1974,10 @@ ScriptLoadRequest* ScriptLoader::LookupPreloadRequest( // This makes sure the pending preload (if exists) for this resource is // properly marked as used and thus not notified in the console as unused. request->NotifyUsage(); + // A used preload must no longer be found in the Document's hash table. Any + // tag after the