From ce6e5a54a00322332188eddc2a358288db7d20c3 Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 7 Jan 2020 21:43:38 +0100 Subject: Cross-browser request properties normalization. --- src/bg/RequestGuard.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js index e57fbba..1ff4269 100644 --- a/src/bg/RequestGuard.js +++ b/src/bg/RequestGuard.js @@ -263,6 +263,15 @@ var RequestGuard = (() => { return redirected; } + let normalizeRequest = UA.isMozilla ? () => {} : request => { + if ("initiator" in request && !("originUrl" in request)) { + request.originUrl = request.initiator; + if (request.type !== "main_frame" && !("documentUrl" in request)) { + request.documentUrl = request.initiator; + } + } + }; + function intersectCapabilities(perms, request) { let {frameId, frameAncestors, tabId} = request; if (frameId !== 0 && ns.sync.cascadeRestrictions) { @@ -282,6 +291,7 @@ var RequestGuard = (() => { const ABORT = {cancel: true}, ALLOW = {}; const listeners = { onBeforeRequest(request) { + normalizeRequest(request); try { let redirected = initPendingRequest(request); let {policy} = ns; @@ -328,6 +338,7 @@ var RequestGuard = (() => { return ALLOW; }, onHeadersReceived(request) { + normalizeRequest(request); let result = ALLOW; let promises = []; // called for main_frame, sub_frame and object @@ -386,6 +397,7 @@ var RequestGuard = (() => { return result; }, onResponseStarted(request) { + normalizeRequest(request); debug("onResponseStarted", request); let {requestId, url, tabId, frameId, type} = request; if (type === "main_frame") { -- cgit v1.2.3