-
Notifications
You must be signed in to change notification settings - Fork 31
Fire information detection events in youtube detector #2439
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
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0df8b19
yt events
jdorweiler e5551b5
update test
jdorweiler 6d472e1
remove extra hostname check
jdorweiler 93bf411
Merge branch 'main' into jd/yt-events
jdorweiler 807bbf4
fix test
jdorweiler dc2e53b
fix: apply prettier formatting to youtube-ad-detection unit tests
jdorweiler 292f33e
fix: handle promise rejection in fireEvent callback
jdorweiler 9c7b8b3
fix: use async/await instead of .catch() in fireEvent callback
jdorweiler b296019
add hostname gating unit tests for runYoutubeAdDetection
jdorweiler 216f94b
add integration tests and debug logging for YouTube detection events
jdorweiler d91b562
Merge branch 'main' into jd/yt-events
jdorweiler 1aa0925
fix: update callback on existing detector singleton
jdorweiler a45e53b
Handle async rejection in onEvent callback to prevent unhandled promi…
cursoragent dbf6b3c
Merge branch 'main' into jd/yt-events
jdorweiler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...tegration-test/test-pages/web-interference-detection/config/youtube-detection-events.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| { | ||
| "readme": "Config for testing YouTube detection event firing via webInterferenceDetection + webEvents", | ||
| "version": 1, | ||
| "unprotectedTemporary": [], | ||
| "features": { | ||
| "webInterferenceDetection": { | ||
| "state": "enabled", | ||
| "hash": "test", | ||
| "exceptions": [], | ||
| "settings": { | ||
| "interferenceTypes": { | ||
| "youtubeAds": { | ||
| "state": "enabled", | ||
| "sweepIntervalMs": 500, | ||
| "slowLoadThresholdMs": 5000, | ||
| "playerSelectors": ["#movie_player"], | ||
| "adClasses": ["ad-showing"], | ||
| "adTextPatterns": [], | ||
| "staticAdSelectors": { "background": "", "thumbnail": "", "image": "" }, | ||
| "playabilityErrorSelectors": [], | ||
| "playabilityErrorPatterns": [], | ||
| "adBlockerDetectionSelectors": ["[role=\"dialog\"]"], | ||
| "adBlockerDetectionPatterns": ["ad\\s*blockers?\\s*(are)?\\s*not allowed"], | ||
| "loginStateSelectors": { | ||
| "signInButton": "", | ||
| "avatarButton": "", | ||
| "premiumLogo": "" | ||
| }, | ||
| "fireDetectionEvents": { | ||
| "adBlocker": true, | ||
| "playabilityError": true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "webEvents": { | ||
| "state": "enabled", | ||
| "hash": "test", | ||
| "exceptions": [] | ||
| } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...ntegration-test/test-pages/web-interference-detection/pages/youtube-detection-events.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>YouTube Detection Events</title> | ||
| </head> | ||
| <body> | ||
| <div id="movie_player" class="html5-video-player"> | ||
| <video src="about:blank"></video> | ||
| </div> | ||
| <div role="dialog" aria-modal="true"> | ||
| <div class="yt-core-attributed-string" role="text">Ad blockers are not allowed on YouTube</div> | ||
| </div> | ||
| </body> | ||
| </html> |
66 changes: 66 additions & 0 deletions
66
injected/integration-test/web-interference-detection-events.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { ResultsCollector } from './page-objects/results-collector.js'; | ||
|
|
||
| const CONFIG_ENABLED = './integration-test/test-pages/web-interference-detection/config/youtube-detection-events.json'; | ||
| const TEST_PAGE = '/web-interference-detection/pages/youtube-detection-events.html'; | ||
|
|
||
| /** | ||
| * @param {ResultsCollector} collector | ||
| * @param {string} method | ||
| */ | ||
| async function getMessagesOfType(collector, method) { | ||
| const calls = await collector.outgoingMessages(); | ||
| return calls.filter((c) => /** @type {import('../../messaging/index.js').NotificationMessage} */ (c.payload).method === method); | ||
| } | ||
|
|
||
| test.describe('YouTube detection events via webInterferenceDetection', () => { | ||
| test('sends webEvent with youtube_adBlocker when ad-blocker modal is detected', async ({ page }, testInfo) => { | ||
| const collector = ResultsCollector.create(page, testInfo.project.use); | ||
| await collector.load(TEST_PAGE, CONFIG_ENABLED); | ||
|
|
||
| await page.waitForTimeout(2000); | ||
|
|
||
| const webEventMessages = await getMessagesOfType(collector, 'webEvent'); | ||
| expect(webEventMessages.length).toBeGreaterThanOrEqual(1); | ||
| const params = | ||
| /** @type {import('../../messaging/index.js').NotificationMessage} */ | ||
| (webEventMessages[0].payload).params; | ||
| expect(params).toEqual({ | ||
| type: 'youtube_adBlocker', | ||
| data: {}, | ||
| }); | ||
| }); | ||
|
|
||
| test('webEvent message has correct structure', async ({ page }, testInfo) => { | ||
| const collector = ResultsCollector.create(page, testInfo.project.use); | ||
| await collector.load(TEST_PAGE, CONFIG_ENABLED); | ||
|
|
||
| await page.waitForTimeout(2000); | ||
|
|
||
| const webEventMessages = await getMessagesOfType(collector, 'webEvent'); | ||
| expect(webEventMessages.length).toBeGreaterThanOrEqual(1); | ||
|
|
||
| for (const msg of webEventMessages) { | ||
| expect(msg.payload.context).toBe('contentScopeScripts'); | ||
| expect(msg.payload.featureName).toBe('webEvents'); | ||
| expect(msg.payload).not.toHaveProperty('nativeData'); | ||
| expect(/** @type {import('../../messaging/index.js').NotificationMessage} */ (msg.payload).params).not.toHaveProperty( | ||
| 'nativeData', | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| test('does not produce page errors during detection and event firing', async ({ page }, testInfo) => { | ||
| const errors = []; | ||
| page.on('pageerror', (error) => errors.push(error)); | ||
|
|
||
| const collector = ResultsCollector.create(page, testInfo.project.use); | ||
| collector.withMockResponse({ webEvent: null }); | ||
| await collector.load(TEST_PAGE, CONFIG_ENABLED); | ||
|
|
||
| await page.waitForTimeout(2000); | ||
|
|
||
| const relevantErrors = errors.filter((e) => !e.message.includes('net::')); | ||
| expect(relevantErrors).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.