duckduckgo / duckduckgo/content-scope-scripts
Use utils' getTabUrl() in tracker-protection instead of recreating
@laghee is already working on this.
Since Mar 12, 2026.
- Dominant language
- JavaScript
- Stars
- 70
- Forks
- 35
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 40
Description
TODO:
- Use utils'
getTabUrl()in tracker-protection instead of internal function
- Delete
getTabURL()fromtracker-protection.js - Import
getTabUrlfrom../utils.js - Replace the single call site (
this._topLevelUrl = getTabURL()ininit()) - Zero behavioral change for tracker-protection since both resolve to the same URL
The two functions are functionally near-identical. Both:
- Try
globalThis.top.location.hreffirst (full URL with path) - On cross-origin
catch, fall back toancestorOrigins(origin-only) anddocument.referrer - Wrap the result in
new URL()with a null-safe catch - Return
URL | null
Minor differences:
| Aspect | utils.js getTabUrl() |
tracker-protection.js getTabURL() |
|---|---|---|
| Fallback priority in catch | ancestorOrigins ?? referrer |
referrer, then ancestorOrigins overrides |
| Null guard on top | @ts-expect-error + bare access |
Optional chaining top?.location.href |
| Null input to URL | Passes null to new URL() (throws, caught) |
Explicit framingOrigin ? guard |
The fallback priority difference is the only semantic one: utils.js prefers ancestorOrigins over referrer (via ??), while tracker-protection.js lets ancestorOrigins override referrer. In practice the result is the same — when ancestorOrigins is available it wins in both cases; the referrer assignment in the tracker-protection version is just overwritten.
- The tracker-protection version was intentionally written with the bugbot-flagged
ancestorOriginsfix already applied (the comment at line 33–34 is explicit about it). Theutils.jsversion arguably has a subtler bug — ifancestorOriginsreturnsnullandreferreris empty string,??picks the empty string (truthy for??but invalid fornew URL). Unifying would be a good opportunity to pick the better implementation and propagate it, but that's a separate discussion. - The dead-code nature makes the change trivial and safe to defer.
A one-line import swap in a fast-follow is low risk and keeps this PR focused on the tracker-protection feature itself.
Originally posted by @cursor[bot] in https://github.com/duckduckgo/content-scope-scripts/pull/2322#discussion_r2925619537
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.