Skip to content

Commit 70cabc1

Browse files
committed
Better report secondary requests with quick redirections
Related issue: - uBlockOrigin/uBlock-issues#1241 uBO will not discard secondary requests fired before a root frame is committed, by ensuring that if newly uncommitted root frames are of the same origin as previous one(s), the uncommited journal slot pointer is not updated.
1 parent 4f53e08 commit 70cabc1

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/js/pagestore.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ const PageStore = class {
226226
constructor(tabId, context) {
227227
this.extraData = new Map();
228228
this.journal = [];
229-
this.journalTimer = null;
230-
this.journalLastCommitted = this.journalLastUncommitted = undefined;
231-
this.journalLastUncommittedURL = undefined;
229+
this.journalTimer = undefined;
230+
this.journalLastCommitted = this.journalLastUncommitted = -1;
231+
this.journalLastUncommittedOrigin = undefined;
232232
this.netFilteringCache = NetFilteringResultCache.factory();
233233
this.init(tabId, context);
234234
}
@@ -351,12 +351,12 @@ const PageStore = class {
351351
this.largeMediaTimer = null;
352352
}
353353
this.disposeFrameStores();
354-
if ( this.journalTimer !== null ) {
354+
if ( this.journalTimer !== undefined ) {
355355
clearTimeout(this.journalTimer);
356-
this.journalTimer = null;
356+
this.journalTimer = undefined;
357357
}
358358
this.journal = [];
359-
this.journalLastUncommittedURL = undefined;
359+
this.journalLastUncommittedOrigin = undefined;
360360
if ( pageStoreJunkyard.length < pageStoreJunkyardMax ) {
361361
pageStoreJunkyard.push(this);
362362
}
@@ -463,7 +463,7 @@ const PageStore = class {
463463
hostname,
464464
result === 1 ? 0x00000001 : 0x00010000
465465
);
466-
if ( this.journalTimer === null ) {
466+
if ( this.journalTimer === undefined ) {
467467
this.journalTimer = vAPI.setTimeout(
468468
( ) => { this.journalProcess(true); },
469469
µb.hiddenSettings.requestJournalProcessPeriod
@@ -475,18 +475,23 @@ const PageStore = class {
475475
if ( type === 'committed' ) {
476476
this.journalLastCommitted = this.journal.length;
477477
if (
478-
this.journalLastUncommitted !== undefined &&
478+
this.journalLastUncommitted !== -1 &&
479479
this.journalLastUncommitted < this.journalLastCommitted &&
480-
this.journalLastUncommittedURL === url
480+
this.journalLastUncommittedOrigin === vAPI.hostnameFromURI(url)
481481
) {
482482
this.journalLastCommitted = this.journalLastUncommitted;
483-
this.journalLastUncommitted = undefined;
484483
}
485484
} else if ( type === 'uncommitted' ) {
486-
this.journalLastUncommitted = this.journal.length;
487-
this.journalLastUncommittedURL = url;
485+
const newOrigin = vAPI.hostnameFromURI(url);
486+
if (
487+
this.journalLastUncommitted === -1 ||
488+
this.journalLastUncommittedOrigin !== newOrigin
489+
) {
490+
this.journalLastUncommitted = this.journal.length;
491+
this.journalLastUncommittedOrigin = newOrigin;
492+
}
488493
}
489-
if ( this.journalTimer !== null ) {
494+
if ( this.journalTimer !== undefined ) {
490495
clearTimeout(this.journalTimer);
491496
}
492497
this.journalTimer = vAPI.setTimeout(
@@ -495,16 +500,14 @@ const PageStore = class {
495500
);
496501
}
497502

498-
journalProcess(fromTimer) {
499-
if ( !fromTimer ) {
500-
clearTimeout(this.journalTimer);
501-
}
502-
this.journalTimer = null;
503+
journalProcess(fromTimer = false) {
504+
if ( fromTimer === false ) { clearTimeout(this.journalTimer); }
505+
this.journalTimer = undefined;
503506

504507
const journal = this.journal;
508+
const pivot = this.journalLastCommitted || 0;
505509
const now = Date.now();
506510
let aggregateCounts = 0;
507-
let pivot = this.journalLastCommitted || 0;
508511

509512
// Everything after pivot originates from current page.
510513
for ( let i = pivot; i < journal.length; i += 2 ) {
@@ -520,7 +523,7 @@ const PageStore = class {
520523
}
521524
this.perLoadBlockedRequestCount += aggregateCounts & 0xFFFF;
522525
this.perLoadAllowedRequestCount += aggregateCounts >>> 16 & 0xFFFF;
523-
this.journalLastCommitted = undefined;
526+
this.journalLastUncommitted = this.journalLastCommitted = -1;
524527

525528
// https://github.com/chrisaljoudi/uBlock/issues/905#issuecomment-76543649
526529
// No point updating the badge if it's not being displayed.

0 commit comments

Comments
 (0)