Skip to content

Commit 196403b

Browse files
author
Shane Osbourne
committed
Added initial duckplayer page without refactor
1 parent 4058a33 commit 196403b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5894
-1561
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"$USER_UNPROTECTED_DOMAINS$": "readonly",
1010
"$CONTENT_SCOPE$": "readonly",
1111
"$TRACKER_LOOKUP$": "readonly",
12-
"$BUNDLED_CONFIG$": "readonly"
12+
"$BUNDLED_CONFIG$": "readonly",
13+
"windowsInteropPostMessage": "readonly",
14+
"windowsInteropAddEventListener": "readonly",
15+
"windowsInteropRemoveEventListener": "readonly"
1316
},
1417
"rules": {
1518
"indent": ["error", 4]

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ let package = Package(
2020
name: "ContentScopeScripts",
2121
dependencies: [],
2222
resources: [
23-
.process("dist")
23+
.process("dist/contentScope.js"),
24+
.copy("dist/pages"),
2425
]
2526
),
2627
]

inject/windows.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function initCode () {
1818

1919
init(processedConfig)
2020

21+
console.log('🪟, init', {
22+
env: import.meta.env
23+
})
24+
2125
// Not supported:
2226
// update(message)
2327
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { test, expect } from '@playwright/test'
2+
import { readFileSync } from 'fs'
3+
import { mockResponse, mockWebkit, mockWindows, removeChromeWebView } from '@duckduckgo/messaging/lib/test-utils.mjs'
4+
5+
test.describe('duckplayer overlays', () => {
6+
test('loads overlays when page is www.youtube.com', async ({ page }, workerInfo) => {
7+
await setup({
8+
page,
9+
configPath: './integration-test/test-pages/duckplayer/config/overlays.json',
10+
// @ts-expect-error
11+
platform: workerInfo.project.use.platform
12+
})
13+
await routeAs({
14+
page,
15+
url: 'https://www.youtube.com',
16+
path: 'integration-test/test-pages/duckplayer/pages/overlays.html'
17+
})
18+
// await page.pause()
19+
await page.locator('.ddg-overlay.ddg-overlay-hover').waitFor({ timeout: 500, state: 'hidden' })
20+
})
21+
test('skips overlay code on none-youtube', async ({ page }, workerInfo) => {
22+
await setup({
23+
page,
24+
configPath: './integration-test/test-pages/duckplayer/config/overlays.json',
25+
// @ts-expect-error
26+
platform: workerInfo.project.use.platform
27+
})
28+
await routeAs({
29+
page,
30+
url: 'https://example.com',
31+
path: 'integration-test/test-pages/duckplayer/pages/overlays.html'
32+
})
33+
expect(await page.locator('.ddg-overlay.ddg-overlay-hover').count()).toEqual(0)
34+
})
35+
})
36+
37+
/**
38+
* @param {object} params
39+
* @param {import("@playwright/test").Page} params.page
40+
* @param {string} params.configPath
41+
* @param {"windows" | "macos"} params.platform
42+
* @return {Promise<void>}
43+
*/
44+
async function setup (params) {
45+
const {
46+
page,
47+
configPath,
48+
platform
49+
} = params
50+
51+
// read remote config from disk
52+
const config = JSON.parse(readFileSync(configPath, 'utf8'))
53+
54+
// choose a JS bundle
55+
const bundle = {
56+
windows: './build/windows/contentScope.js',
57+
apple: './Sources/ContentScopeScripts/dist/contentScope.js'
58+
}[platform]
59+
60+
// read the build file from disk
61+
const build = readFileSync(bundle, 'utf8')
62+
63+
// setup windows messaging mocks
64+
const messagingMocks = {
65+
windows: mockWindows,
66+
apple: mockWebkit
67+
}[platform]
68+
69+
await page.addInitScript(messagingMocks, {
70+
messagingContext: {
71+
env: 'development',
72+
context: 'contentScopeScripts',
73+
featureName: 'duckPlayer'
74+
}
75+
})
76+
77+
// any additional mock setup
78+
if (platform === 'windows') {
79+
await page.addInitScript(removeChromeWebView)
80+
}
81+
82+
// setup global injected vars
83+
await page.addInitScript((params) => Object.assign(globalThis, params), {
84+
$CONTENT_SCOPE$: config,
85+
$USER_UNPROTECTED_DOMAINS$: [],
86+
$USER_PREFERENCES$: {
87+
platform: { name: platform }
88+
}
89+
})
90+
91+
// add the default mock responses - just enough to get the page working
92+
await page.addInitScript(mockResponse, {
93+
responses: {
94+
getUserValues: {
95+
privatePlayerMode: { alwaysAsk: {} },
96+
overlayInteracted: false
97+
}
98+
}
99+
})
100+
101+
// attach the JS
102+
await page.addInitScript(build)
103+
}
104+
105+
/**
106+
* @param {object} params
107+
* @param {import("@playwright/test").Page} params.page
108+
* @param {string} params.url
109+
* @param {string} params.path
110+
* @return {Promise<void>}
111+
*/
112+
async function routeAs (params) {
113+
const {
114+
page,
115+
url,
116+
path
117+
} = params
118+
119+
// fake a url load
120+
await page.route(url, (route, request) => {
121+
console.log(request.url())
122+
return route.fulfill({ path })
123+
})
124+
125+
// navigate to the url
126+
await page.goto(url)
127+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"unprotectedTemporary": [],
3+
"features": {
4+
"duckPlayer": {
5+
"state": "enabled",
6+
"exceptions": [],
7+
"settings": {
8+
"overlays": [
9+
{
10+
"domain": "www.youtube.com",
11+
"state": "enabled"
12+
}
13+
],
14+
"proxy": [
15+
{
16+
"domain": "duckduckgo.com",
17+
"state": "enabled"
18+
}
19+
]
20+
}
21+
}
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"features": {
3+
"duckPlayer": {
4+
"state": "enabled",
5+
"exceptions": [],
6+
"settings": {
7+
"overlays": "disabled",
8+
"proxy": "disabled",
9+
"domains": [
10+
{
11+
"domain": "localhost",
12+
"patchSettings": [
13+
{ "op": "replace", "path": "/proxy", "value": "enabled" }
14+
]
15+
}
16+
]
17+
}
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Runtime checks</title>
7+
</head>
8+
<body>
9+
<p><a href="../../index.html">[Home]</a></p>
10+
11+
<p>Duck Player</p>
12+
<ul>
13+
<li><a href="./pages/basic-run.html">Basic Run</a> - <a href="./config/basic-run.json">Config</a></li>
14+
<li><a href="./pages/filter-props.html">Filter props</a> - <a href="./config/filter-props.json">Config</a></li>
15+
<li><a href="./pages/script-overload.html">Script overloading</a> - <a href="./config/script-overload.json">Config</a></li>
16+
<li><a href="./pages/shadow-dom.html">Shadow dom support</a> - <a href="./config/shadow-dom.json">Config</a></li>
17+
</ul>
18+
19+
</body>
20+
</html>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Runtime checks</title>
7+
<link rel="stylesheet" href="../../shared/style.css">
8+
<style>
9+
#thumbnail {
10+
height: 100px;
11+
width: 200px;
12+
margin: 5px;
13+
background: lightblue;
14+
border: 1px solid black;
15+
float: left;
16+
}
17+
18+
#thumbnail img {
19+
width: 100%;
20+
height: 100%;
21+
}
22+
23+
#playlist {
24+
clear: both;
25+
width: 100px;
26+
27+
}
28+
29+
#playlist #items {
30+
height: 150px;
31+
overflow: auto;
32+
}
33+
34+
#playlist #thumbnail {
35+
width: 90px;
36+
height: 50px;
37+
}
38+
39+
#loaded {
40+
clear: both;
41+
float: none;
42+
width: 300px;
43+
}
44+
45+
h2 {
46+
padding-top: 2em;
47+
}
48+
</style>
49+
</head>
50+
<body>
51+
<script src="../../shared/utils.js"></script>
52+
<p><a href="../index.html">[Duck Player]</a></p>
53+
54+
<div id="initial"></div>
55+
<div id="loaded"></div>
56+
57+
<script>
58+
const thumbnail = id => `<a id="thumbnail" href="/watch?v=${id}"><img src="//:0"></a>`;
59+
const thumbnails = title => (title ? '<h2>'+title+'</h2>' : '') + '<div class="thumbnails" data-testid="'+title+'">' + ([1,2,3,4,5]).map(thumbnail).join('') + '</div>';
60+
const playlist = title => `<div id="playlist"><h2>${title}</h2><div id="items" class="playlist-items" data-testid="${title}">${thumbnails()}</div></div>`;
61+
document.querySelector('#initial').innerHTML = thumbnails('THUMBNAILS') + playlist('PLAYLIST') + thumbnails('MORE THUMBNAILS');
62+
</script>
63+
64+
<script>
65+
// eslint-disable-next-line no-undef
66+
test('should thing', async () => {
67+
console.log('haha');
68+
69+
await new Promise(res => setTimeout(res, 20000));
70+
71+
return [
72+
{
73+
name: 'enabled',
74+
result: false,
75+
expected: true
76+
},
77+
]
78+
})
79+
80+
// eslint-disable-next-line no-undef
81+
renderResults()
82+
</script>
83+
</body>
84+
</html>

0 commit comments

Comments
 (0)