diff --git a/lib/fetch/util.js b/lib/fetch/util.js index d1b21221b57..c62d3ff7b01 100644 --- a/lib/fetch/util.js +++ b/lib/fetch/util.js @@ -298,19 +298,30 @@ function determineRequestsReferrer (request) { // TODO // 3(a) If policy is "origin", then // 3(a)(I) If environment's global object is Window then - - // 3(a)(II) If environment's global object is not Window, - // Let referrerSource be environments creationURL - - // 3(b) If requests's referrer is a URL instance, then make - // referrerSource be requests's referrer. - if (request.referrer instanceof URL) { + if (request.referrer === 'client') { + if (environment.globalObject instanceof Window) { + const origin = environment.globalObject.self?.origin ?? environment.globalObject.location?.origin + + if (origin == null || origin === 'null') return 'no-referrer' + referrerSource = new URL(environment.globalObject.location.href) + } else { + // 3(a)(II) If environment's global object is not Window, + // Let referrerSource be environments creationURL + if (environment.globalObject.location == null) { + return 'no-referrer' + } + + referrerSource = new URL(environment.globalObject.location.href) + } + } else if (request.referrer instanceof URL) { + // 3(b) If requests's referrer is a URL instance, then make + // referrerSource be requests's referrer. referrerSource = request.referrer + } else { + // If referrerSource is null, then return "no-referrer". + return 'no-referrer' } - // If referrerSource is null, then return "no-referrer". - if (referrerSource === null) return 'no-referrer' - const urlProtocol = referrerSource.protocol // If url's scheme is a local scheme (i.e. one of "about", "data", "javascript", "file")