Skip to content

Commit

Permalink
feat: add check for window
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Feb 20, 2022
1 parent 5497bdc commit 626cd04
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 626cd04

Please sign in to comment.