From 1ddb822509bca59fd4f7655af9d7d0c84d357acd Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 21 May 2019 11:21:34 -0400 Subject: [PATCH] Mitigate undesireable side-effect of 901c325eabcc Related discussion/issue: - https://github.com/uBlockOrigin/uMatrix-issues/issues/156#issuecomment-494427094 - https://github.com/uBlockOrigin/uMatrix-issues/issues/155 Due to a Chromium issue about not providing the proper context information, a negative side-effect was introduced with fix to #155. This commit will force the originator of a network request of type `main_frame` to be that of the request URL itself, i.e. the originator of a top-level document request is the requested document itself. --- platform/chromium/vapi-webrequest.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/chromium/vapi-webrequest.js b/platform/chromium/vapi-webrequest.js index 2bb0794..034a1ec 100644 --- a/platform/chromium/vapi-webrequest.js +++ b/platform/chromium/vapi-webrequest.js @@ -71,17 +71,21 @@ const parsedURL = new URL('https://www.example.org/'); vAPI.net.normalizeDetails = function(details) { + let type = details.type; + + // https://github.com/uBlockOrigin/uMatrix-issues/issues/156#issuecomment-494427094 + if ( type === 'main_frame' ) { + details.documentUrl = details.url; + } // Chromium 63+ supports the `initiator` property, which contains // the URL of the origin from which the network request was made. - if ( + else if ( typeof details.initiator === 'string' && details.initiator !== 'null' ) { details.documentUrl = details.initiator; } - let type = details.type; - // https://github.com/gorhill/uBlock/issues/1493 // Chromium 49+/WebExtensions support a new request type: `ping`, // which is fired as a result of using `navigator.sendBeacon`.