Fix improper partiness attribution for some delayed network requests

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2453
This commit is contained in:
Raymond Hill 2023-01-28 11:38:53 -05:00
parent 99ac234d12
commit 6fd58c9c9b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 33 additions and 19 deletions

View File

@ -273,13 +273,22 @@ const µBlock = { // jshint ignore:line
return this; return this;
} }
maybeFromDocumentURL(documentUrl) {
if ( documentUrl === undefined ) { return; }
if ( documentUrl.startsWith(this.tabOrigin) ) { return; }
this.tabOrigin = originFromURI(µBlock.normalizeTabURL(0, documentUrl));
this.tabHostname = hostnameFromURI(this.tabOrigin);
this.tabDomain = domainFromHostname(this.tabHostname);
}
// https://github.com/uBlockOrigin/uBlock-issues/issues/459 // https://github.com/uBlockOrigin/uBlock-issues/issues/459
// In case of a request for frame and if ever no context is specified, // In case of a request for frame and if ever no context is specified,
// assume the origin of the context is the same as the request itself. // assume the origin of the context is the same as the request itself.
fromWebrequestDetails(details) { fromWebrequestDetails(details) {
const tabId = details.tabId; const tabId = details.tabId;
this.type = details.type; this.type = details.type;
if ( this.itype === this.MAIN_FRAME && tabId > 0 ) { const isMainFrame = this.itype === this.MAIN_FRAME;
if ( isMainFrame && tabId > 0 ) {
µBlock.tabContextManager.push(tabId, details.url); µBlock.tabContextManager.push(tabId, details.url);
} }
this.fromTabId(tabId); // Must be called AFTER tab context management this.fromTabId(tabId); // Must be called AFTER tab context management
@ -288,6 +297,8 @@ const µBlock = { // jshint ignore:line
this.setMethod(details.method); this.setMethod(details.method);
this.setURL(details.url); this.setURL(details.url);
this.aliasURL = details.aliasURL || undefined; this.aliasURL = details.aliasURL || undefined;
this.redirectURL = undefined;
this.filter = undefined;
if ( this.itype !== this.SUB_FRAME ) { if ( this.itype !== this.SUB_FRAME ) {
this.docId = details.frameId; this.docId = details.frameId;
this.frameId = -1; this.frameId = -1;
@ -297,12 +308,18 @@ const µBlock = { // jshint ignore:line
} }
if ( this.tabId > 0 ) { if ( this.tabId > 0 ) {
if ( this.docId === 0 ) { if ( this.docId === 0 ) {
if ( isMainFrame === false ) {
this.maybeFromDocumentURL(details.documentUrl);
}
this.docOrigin = this.tabOrigin; this.docOrigin = this.tabOrigin;
this.docHostname = this.tabHostname; this.docHostname = this.tabHostname;
this.docDomain = this.tabDomain; this.docDomain = this.tabDomain;
} else if ( details.documentUrl !== undefined ) { return this;
}
if ( details.documentUrl !== undefined ) {
this.setDocOriginFromURL(details.documentUrl); this.setDocOriginFromURL(details.documentUrl);
} else { return this;
}
const pageStore = µBlock.pageStoreFromTabId(this.tabId); const pageStore = µBlock.pageStoreFromTabId(this.tabId);
const docStore = pageStore && pageStore.getFrameStore(this.docId); const docStore = pageStore && pageStore.getFrameStore(this.docId);
if ( docStore ) { if ( docStore ) {
@ -310,20 +327,17 @@ const µBlock = { // jshint ignore:line
} else { } else {
this.setDocOrigin(this.tabOrigin); this.setDocOrigin(this.tabOrigin);
} }
return this;
} }
} else if ( details.documentUrl !== undefined ) { if ( details.documentUrl !== undefined ) {
const origin = originFromURI( const origin = originFromURI(
µBlock.normalizeTabURL(0, details.documentUrl) µBlock.normalizeTabURL(0, details.documentUrl)
); );
this.setDocOrigin(origin).setTabOrigin(origin); this.setDocOrigin(origin).setTabOrigin(origin);
} else if ( this.docId === -1 || (this.itype & this.FRAME_ANY) !== 0 ) { return this;
}
const origin = originFromURI(this.url); const origin = originFromURI(this.url);
this.setDocOrigin(origin).setTabOrigin(origin); this.setDocOrigin(origin).setTabOrigin(origin);
} else {
this.setDocOrigin(this.tabOrigin);
}
this.redirectURL = undefined;
this.filter = undefined;
return this; return this;
} }