Skip to content

Setting of document for tracker analysis #1613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion injected/src/trackers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { getGlobal } from './utils.js';

/**
* Check if the current document origin is on the tracker list, using the provided lookup trie.
* @param {object} trackerLookup Trie lookup of tracker domains
* @returns {boolean} True iff the origin is a tracker.
*
* Note: getGlobal() is used in testing to get the global object,
* it's a work around for ESM modules are essentially singletons preventing overriding of global variables.
*/
export function isTrackerOrigin(trackerLookup, originHostname = document.location.hostname) {
export function isTrackerOrigin(trackerLookup, originHostname = getGlobal().document.location.hostname) {
const parts = originHostname.split('.').reverse();
let node = trackerLookup;
for (const sub of parts) {
Expand Down
8 changes: 8 additions & 0 deletions injected/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ export function setGlobal(globalObjIn) {
Error = globalObj.Error;
}

/**
* Used for testing to allow other files to override the globals used within this file.
* @returns {globalThis} the global object
*/
export function getGlobal() {
return globalObj;
}

// linear feedback shift register to find a random approximation
export function nextRandom(v) {
return Math.abs((v >> 1) | (((v << 62) ^ (v << 61)) & (~(~0 << 63) << 62)));
Expand Down
Loading