Skip to content

Add video playback observer #1721

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 23 commits into from
Jul 16, 2025
Merged

Add video playback observer #1721

merged 23 commits into from
Jul 16, 2025

Conversation

RendijsSmukulis
Copy link
Contributor

@RendijsSmukulis RendijsSmukulis commented Jun 5, 2025

Asana Task/Github Issue: https://app.asana.com/1/137249556945/project/1163321984198618/task/1210574035464142?focus=true

Description

Watches for video plays so they can be counted on the native side.

Relevant config change: duckduckgo/privacy-configuration#3452

Testing Steps

Checklist

Please tick all that apply:

  • I have tested this change locally
  • I have tested this change locally in all supported browsers
  • This change will be visible to users
  • I have added automated tests that cover this change
  • I have ensured the change is gated by config
  • This change was covered by a ship review
  • This change was covered by a tech design
  • Any dependent config has been merged

Copy link

netlify bot commented Jun 5, 2025

Deploy Preview for content-scope-scripts ready!

Name Link
🔨 Latest commit fbdd18a
🔍 Latest deploy log https://app.netlify.com/projects/content-scope-scripts/deploys/6877ce8eacd1620008532a42
😎 Deploy Preview https://deploy-preview-1721--content-scope-scripts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

github-actions bot commented Jun 5, 2025

Temporary Branch Update

The temporary branch has been updated with the latest changes. Below are the details:

Please use the above install command to update to the latest version.

Copy link

github-actions bot commented Jun 5, 2025

[Beta] Generated file diff

Time updated: Wed, 16 Jul 2025 16:12:58 GMT

Android
    - android/autofillPasswordImport.js
  • android/brokerProtection.js
  • android/contentScope.js

File has changed

Chrome-mv3
    - chrome-mv3/inject.js

File has changed

Firefox
    - firefox/inject.js

File has changed

Integration
    - integration/contentScope.js

File has changed

Windows
    - windows/contentScope.js

File has changed

Apple
    - dist/contentScope.js
  • dist/contentScopeIsolated.js

File has changed

@jonathanKingston jonathanKingston marked this pull request as ready for review July 15, 2025 13:34
@jonathanKingston jonathanKingston requested review from kzar, sammacbeth and a team as code owners July 15, 2025 13:34
@jonathanKingston jonathanKingston requested a review from a team as a code owner July 15, 2025 13:34
cursor[bot]

This comment was marked as outdated.

@rachelmcr
Copy link

@jonathanKingston Are there specific testing steps that should be used for this PR? I haven’t reviewed C-S-S changes before, so just checking what I should be watching out for here from an Apple perspective. (Also, the title says this is a WIP, is that intentional?)

@jonathanKingston jonathanKingston marked this pull request as draft July 16, 2025 10:39
@jonathanKingston jonathanKingston changed the title [wip] Add video playback observer Add video playback observer Jul 16, 2025
@jonathanKingston jonathanKingston marked this pull request as ready for review July 16, 2025 16:12
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Video Telemetry Bugs: Deduplication and API Compatibility

The WebTelemetry feature has two issues:

  1. Incomplete Video Deduplication: Telemetry events for videos without a discernible URL are not properly deduplicated. The fireTelemetryForVideo method checks for null in the seenVideoUrls set but never adds null to it, causing repeated telemetry events for the same video.
  2. API Compatibility Error: Accessing navigator.userActivation.isActive without checking for the userActivation API's availability can cause a runtime error in unsupported environments, breaking telemetry.

injected/src/features/web-telemetry.js#L33-L48

fireTelemetryForVideo(video) {
const videoUrl = this.getVideoUrl(video);
if (this.seenVideoUrls.has(videoUrl)) {
return;
}
// If we have a URL, store it just to deduplicate
// This will clear on page change and isn't sent to native/server.
if (videoUrl) {
this.seenVideoUrls.add(videoUrl);
}
const message = {
userInteraction: navigator.userActivation.isActive,
};
this.messaging.notify(MSG_VIDEO_PLAYBACK, message);
}

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@RendijsSmukulis RendijsSmukulis merged commit 87c0feb into main Jul 16, 2025
22 checks passed
@RendijsSmukulis RendijsSmukulis deleted the jkt/video-playback branch July 16, 2025 16:21
mallexxx pushed a commit that referenced this pull request Jul 17, 2025
* Add video playback observer

* Enable webCompat on Windows

* Call on document load

* Move to telemetry

* Fix comment that was stolen

* Add PoC test case

* Add video listener

* Listen earlier, dedupe messages

* Check for presence of node

* Make observer use documentElement as a fallback for a listener

* Use notify as a fire and forget

* Call messaging in the correct scope

* Simplify

* Use once listeners instead

* add args to constructor

* Add play watch on start

* Fix scope

* Cleanup

* Rename to web-telemetry

* Account for video tag reuse by deduping against URL instead

* Bail out on seen urls

---------

Co-authored-by: Jonathan Kingston <jkingston@duckduckgo.com>
Co-authored-by: Jonathan Kingston <jonathan@jooped.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants