Skip to content

Commit 4f85178

Browse files
shakyShaneShane Osbourne
and
Shane Osbourne
authored
fix(duckplayer): ensure overlay shows when DOM is added incrementally (#593)
Co-authored-by: Shane Osbourne <[email protected]>
1 parent 4750d59 commit 4f85178

File tree

5 files changed

+83
-21
lines changed

5 files changed

+83
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ node_modules/
44
.env
55
build/
66
docs/
7+
test-results/
8+
playwright-report/
79
Sources/ContentScopeScripts/dist/

integration-test/playwright/duckplayer.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ test.describe('Duck Player Overlays on Video Player in YouTube.com', () => {
108108
// Then then the overlay shows and blocks the video from playing
109109
await overlays.overlayBlocksVideo()
110110
})
111+
test('Overlay blocks video from playing (supporting DOM appearing over time)', async ({ page }, workerInfo) => {
112+
const overlays = DuckplayerOverlays.create(page, workerInfo)
113+
114+
// Given overlays feature is enabled
115+
await overlays.overlaysEnabled()
116+
117+
// And my setting is 'always ask'
118+
await overlays.userSettingIs('always ask')
119+
await overlays.gotoPlayerPage({ variant: 'incremental-dom' })
120+
121+
// Then then the overlay shows and blocks the video from playing
122+
await overlays.overlayBlocksVideo()
123+
})
111124
test('Overlay is removed when new settings arrive', async ({ page }, workerInfo) => {
112125
const overlays = DuckplayerOverlays.create(page, workerInfo)
113126

integration-test/playwright/page-objects/duckplayer-overlays.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,19 @@ export class DuckplayerOverlays {
5454
await this.page.goto(this.overlaysPage)
5555
}
5656

57-
async gotoPlayerPage () {
58-
await this.page.goto(this.playerPage + '?videoID=123')
57+
/**
58+
* @param {object} [params]
59+
* @param {"default" | "incremental-dom"} [params.variant]
60+
* - we are replicating different strategies in the HTML to capture regressions/bugs
61+
*/
62+
async gotoPlayerPage (params = {}) {
63+
const { variant = 'default' } = params
64+
const urlParams = new URLSearchParams([
65+
['videoID', '123'],
66+
['variant', variant]
67+
])
68+
69+
await this.page.goto(this.playerPage + '?' + urlParams.toString())
5970
}
6071

6172
async gotoSerpProxyPage () {

integration-test/test-pages/duckplayer/pages/player.html

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,33 @@
66
<title>Duck Player - Player Overlay</title>
77
<link rel="stylesheet" href="../../shared/style.css">
88
<style>
9+
*, *:before, *:after {
10+
box-sizing: border-box;
11+
}
912
.container {
10-
width: 800px;
11-
height: 600px;
13+
max-width: 800px;
14+
aspect-ratio: 16/9;
1215
background: blue;
1316
}
17+
#player {
18+
height: 100%;
19+
}
1420
.html5-video-player {
1521
position: relative;
22+
height: 100%;
23+
border: 2px dotted red;
1624
}
1725
body {
1826
max-width: 100%;
1927
}
2028
.tools {
2129
margin-bottom: 1rem;
2230
}
31+
video {
32+
display: block;
33+
height: 100%;
34+
width: 100%;
35+
}
2336
</style>
2437
</head>
2538
<body>
@@ -39,8 +52,36 @@
3952
</div>
4053
</div>
4154
</template>
55+
4256
<script type="module">
43-
document.querySelector('main').innerHTML = document.querySelector('template[id="inner"]').innerHTML;
57+
const variant = new URLSearchParams(window.location.search).get('variant') || 'default';
58+
const main = document.querySelector('main');
59+
const html = (selector) => document.querySelector(selector).innerHTML
60+
61+
const knownVariants = {
62+
"default": () => {
63+
main.innerHTML = html('template[id="inner"]');
64+
},
65+
"incremental-dom": () => {
66+
main.innerHTML = `<div class="container"><div id="player"></div></div>`
67+
setTimeout(() => {
68+
const player = main.querySelector('#player');
69+
player.innerHTML = `
70+
<div class="html5-video-player">
71+
<video width="800px" height="600px"></video>
72+
</div>
73+
`
74+
}, 100);
75+
},
76+
}
77+
78+
if (variant in knownVariants) {
79+
console.log('executing page variant', variant)
80+
knownVariants[variant]();
81+
} else {
82+
console.warn('variant not found', variant)
83+
}
84+
4485
</script>
4586
</body>
4687
</html>

src/features/duckplayer/video-overlay-manager.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,6 @@ export class VideoOverlayManager {
7676
})
7777
}
7878

79-
/**
80-
* Set up the overlay
81-
* @param {import("../duck-player.js").UserValues} userValues
82-
* @param {import("./util").VideoParams} params
83-
*/
84-
addLargeOverlay (userValues, params) {
85-
const playerVideo = document.querySelector('#player video')
86-
const containerElement = document.querySelector('#player .html5-video-player')
87-
88-
if (playerVideo && containerElement) {
89-
this.stopVideoFromPlaying(playerVideo)
90-
this.appendOverlayToPage(containerElement, params)
91-
}
92-
}
93-
9479
/**
9580
* @param {import("./util").VideoParams} params
9681
*/
@@ -138,6 +123,15 @@ export class VideoOverlayManager {
138123
return null
139124
}
140125

126+
/**
127+
* Don't continue until we've been able to find the HTML elements that we inject into
128+
*/
129+
const videoElement = playerElement.querySelector('video')
130+
const playerContainer = playerElement.querySelector('.html5-video-player')
131+
if (!videoElement || !playerContainer) {
132+
return null
133+
}
134+
141135
/**
142136
* If we get here, it's a valid situation
143137
*/
@@ -158,7 +152,8 @@ export class VideoOverlayManager {
158152
if ('alwaysAsk' in userValues.privatePlayerMode) {
159153
if (!userValues.overlayInteracted) {
160154
if (!this.environment.hasOneTimeOverride()) {
161-
this.addLargeOverlay(userValues, params)
155+
this.stopVideoFromPlaying(videoElement)
156+
this.appendOverlayToPage(playerContainer, params)
162157
}
163158
} else {
164159
this.addSmallDaxOverlay(params)

0 commit comments

Comments
 (0)