Skip to content

Commit

Permalink
AG-27583 fix multiple injection to the pages for mv2
Browse files Browse the repository at this point in the history
  • Loading branch information
maximtop committed Nov 19, 2024
1 parent 8cf7d96 commit 27664ce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { EngineApi } from '../engine-api';
import type { DocumentApi } from '../document-api';
import type { TabsApi } from './tabs-api';
import { MAIN_FRAME_ID } from '../../../common/constants';
import { appContext } from '../context';

/**
* Injects cosmetic rules into tabs, opened before app initialization.
Expand Down Expand Up @@ -100,6 +101,20 @@ export class TabsCosmeticInjector {
return;
}

/**
* This value was determined through experimentation
* and should provide sufficient time for the engine to initialize.
*/
const TAB_PROCESSING_THRESHOLD_MS = 10000;

/**
* This condition prevents applying cosmetic rules to the tab multiple times.
* Applying them once after the extension's initialization is sufficient.
*/
if (appContext.startTimeMs && Date.now() - appContext.startTimeMs > TAB_PROCESSING_THRESHOLD_MS) {
return;
}

const cosmeticOption = frame.matchingResult.getCosmeticOption();

frame.cosmeticResult = this.engineApi.getCosmeticResult(frameUrl, cosmeticOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ export class TabsCosmeticInjector {
documentId,
});

/**
* This value was determined through experimentation
* and should provide enough time for the engine to initialize.
*/
const TAB_PROCESSING_THRESHOLD_MS = 10000;

/**
* This condition prevents applying cosmetic rules to the tab multiple times.
* Applying them once after the extension's initialization is sufficient.
* Applying them once after the extension's initialization is enough.
*/
if (appContext.startTimeMs && (currentTime - appContext.startTimeMs) > 10000) {
if (appContext.startTimeMs && currentTime - appContext.startTimeMs > TAB_PROCESSING_THRESHOLD_MS) {
return;
}

Expand Down

0 comments on commit 27664ce

Please sign in to comment.