Skip to content

Comments

Add URL tracking parameter stripping for clipboard#1833

Open
ftlframe wants to merge 2 commits intofuto-org:masterfrom
ftlframe:feature/strip-url-tracking-params
Open

Add URL tracking parameter stripping for clipboard#1833
ftlframe wants to merge 2 commits intofuto-org:masterfrom
ftlframe:feature/strip-url-tracking-params

Conversation

@ftlframe
Copy link

Closes #556 - automatically removes tracking parameters
(utm_*, fbclid, si, etc.) from URLs copied to the clipboard using the ClearURLs ruleset.

  • Add UrlCleaner.kt utility that parses url-rules.json and strips tracking params
  • Add ClipboardStripUrlTracking setting (disabled by default)
  • Modify ClipboardHistoryManager to clean URLs when copied
  • Modify QuickClip to display cleaned URLs in suggestion bar
  • Add url-rules.json from ClearURLs project to assets

Testing:

  • "Remove URL tracking parameters" in Clipboard settings
  • URLs with tracking params (YouTube, Amazon, etc.)
  • Verify tracking params are stripped when pasted

   Implements GitHub issue futo-org#556 - automatically removes tracking parameters
   (utm_*, fbclid, si, etc.) from URLs copied to the clipboard using the ClearURLs ruleset.
   - Add UrlCleaner.kt utility that parses url-rules.json and strips tracking params
   - Add ClipboardStripUrlTracking setting (disabled by default)
   - Modify ClipboardHistoryManager to clean URLs when copied
   - Modify QuickClip to display cleaned URLs in suggestion bar
   - Add url-rules.json from ClearURLs project to assets
@futo-cla-pr-labler
Copy link

Please sign our contributor license agreement at https://cla.futo.org

1 similar comment
@futo-cla-pr-labler
Copy link

Please sign our contributor license agreement at https://cla.futo.org

Copy link
Collaborator

@abb128 abb128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I haven't tested the changes yet but a couple things stood out to me in the code

Comment on lines 310 to 322
// Clean URL tracking params if enabled
if (text != null && context.getSettingBlocking(ClipboardStripUrlTracking)) {
val cleanedText = UrlCleaner.cleanUrl(text);
if(cleanedText != text) {
// Update system clipboard with clean URL
val newClip = ClipData.newPlainText(
clip.description?.label ?: "text", cleanedText
);

clipboardManager.setPrimaryClip(newClip);
return; // Exit and trigger onPrimaryClipChanged again with clean text
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this would discard EXTRA_IS_SENSITIVE if it was set. Do you think it would be better to just avoid touching the clip if it's marked sensitive?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, went over my head. I'll add a check to skip cleaning if the clip is marked sensitive

// We just find the URL in text, discarding the https:// part
val urlRegex = """https?://\S+""".toRegex();

return urlRegex.replace(text) { matchResult ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should be scanning the string for all URLs and changing them individually. If someone is copying a bunch of code, or a long document, etc, it might be unexpected for the keyboard to silently change URLs in the middle and it might break stuff. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, I'll change this aswell to be used for the more common case of just copying links and just skip longer documents etc..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abb128 Both are fixed, ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA-signed Enhancement Request for a new feature Privacy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Tracking Parameters from URLs

3 participants