Skip to content

Commit bfc9351

Browse files
Release build 4.12.0 [ci release]
1 parent 7bb92c3 commit bfc9351

Some content is hidden

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

62 files changed

+45022
-61885
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ jobs:
5454
${{ runner.os }}-node-
5555
- name: Install dependencies
5656
run: |
57-
sudo apt-get install xvfb
5857
npm install
5958
npm run build
6059
- name: Cache docs output
@@ -65,6 +64,13 @@ jobs:
6564
key: docs-output-${{ github.run_id }}
6665
- name: Install Playwright Browsers
6766
run: npx playwright install --with-deps
67+
- run: npm run playwright
68+
- uses: actions/upload-artifact@v2
69+
if: always()
70+
with:
71+
name: playwright-report
72+
path: playwright-report/
73+
retention-days: 5
6874
- run: npm run test-int-x
6975
- name: Build docs
7076
run: npm run docs

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 1488 additions & 7179 deletions
Large diffs are not rendered by default.

build/android/contentScope.js

Lines changed: 1619 additions & 7353 deletions
Large diffs are not rendered by default.

build/chrome-mv3/inject.js

Lines changed: 6509 additions & 9538 deletions
Large diffs are not rendered by default.

build/chrome/inject.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/contentScope.js

Lines changed: 9678 additions & 9507 deletions
Large diffs are not rendered by default.

build/firefox/inject.js

Lines changed: 6588 additions & 9618 deletions
Large diffs are not rendered by default.

build/integration/contentScope.js

Lines changed: 9678 additions & 9507 deletions
Large diffs are not rendered by default.

build/integration/pages/duckplayer/js/index.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
__publicField(this, "config");
1919
this.messagingContext = messagingContext;
2020
this.config = config;
21+
this.globals = {
22+
window,
23+
JSONparse: window.JSON.parse,
24+
JSONstringify: window.JSON.stringify,
25+
Promise: window.Promise,
26+
Error: window.Error,
27+
String: window.String
28+
};
2129
for (const [methodName, fn] of Object.entries(this.config.methods)) {
2230
if (typeof fn !== "function") {
2331
throw new Error("cannot create WindowsMessagingTransport, missing the method: " + methodName);
@@ -28,7 +36,8 @@
2836
* @param {import('../index.js').NotificationMessage} msg
2937
*/
3038
notify(msg) {
31-
const notification = WindowsNotification.fromNotification(msg);
39+
const data = this.globals.JSONparse(this.globals.JSONstringify(msg.params || {}));
40+
const notification = WindowsNotification.fromNotification(msg, data);
3241
this.config.methods.postMessage(notification);
3342
}
3443
/**
@@ -37,31 +46,32 @@
3746
* @return {Promise<any>}
3847
*/
3948
request(msg, opts = {}) {
40-
const outgoing = WindowsRequestMessage.fromRequest(msg);
49+
const data = this.globals.JSONparse(this.globals.JSONstringify(msg.params || {}));
50+
const outgoing = WindowsRequestMessage.fromRequest(msg, data);
4151
this.config.methods.postMessage(outgoing);
4252
const comparator = (eventData) => {
4353
return eventData.featureName === msg.featureName && eventData.context === msg.context && eventData.id === msg.id;
4454
};
45-
function isMessageResponse(data) {
46-
if ("result" in data)
55+
function isMessageResponse(data2) {
56+
if ("result" in data2)
4757
return true;
48-
if ("error" in data)
58+
if ("error" in data2)
4959
return true;
5060
return false;
5161
}
52-
return new Promise((resolve, reject) => {
62+
return new this.globals.Promise((resolve, reject) => {
5363
try {
5464
this._subscribe(comparator, opts, (value, unsubscribe) => {
5565
unsubscribe();
5666
if (!isMessageResponse(value)) {
5767
console.warn("unknown response type", value);
58-
return reject(new Error("unknown response"));
68+
return reject(new this.globals.Error("unknown response"));
5969
}
6070
if (value.result) {
6171
return resolve(value.result);
6272
}
63-
const message = String(value.error?.message || "unknown error");
64-
reject(new Error(message));
73+
const message = this.globals.String(value.error?.message || "unknown error");
74+
reject(new this.globals.Error(message));
6575
});
6676
} catch (e) {
6777
reject(e);
@@ -158,9 +168,9 @@
158168
* @param {NotificationMessage} notification
159169
* @returns {WindowsNotification}
160170
*/
161-
static fromNotification(notification) {
171+
static fromNotification(notification, data) {
162172
const output = {
163-
Data: JSON.parse(JSON.stringify(notification.params || {})),
173+
Data: data,
164174
Feature: notification.context,
165175
SubFeatureName: notification.featureName,
166176
Name: notification.method
@@ -188,11 +198,12 @@
188198
/**
189199
* Helper to convert a {@link RequestMessage} to a format that Windows can support
190200
* @param {RequestMessage} msg
201+
* @param {Record<string, any>} data
191202
* @returns {WindowsRequestMessage}
192203
*/
193-
static fromRequest(msg) {
204+
static fromRequest(msg, data) {
194205
const output = {
195-
Data: JSON.parse(JSON.stringify(msg.params || {})),
206+
Data: data,
196207
Feature: msg.context,
197208
SubFeatureName: msg.featureName,
198209
Name: msg.method,
@@ -826,15 +837,11 @@
826837
* Sets the tab title to the title of the video once the video title has loaded.
827838
*/
828839
setTabTitle: () => {
829-
let hasGottenValidVideoTitle = false;
830840
VideoPlayer.onIframeLoaded(() => {
831841
VideoPlayer.onIframeTitleChange((title) => {
832-
if (!hasGottenValidVideoTitle) {
833-
const validTitle = VideoPlayer.getValidVideoTitle(title);
834-
if (validTitle) {
835-
document.title = "Duck Player - " + validTitle;
836-
hasGottenValidVideoTitle = true;
837-
}
842+
const validTitle = VideoPlayer.getValidVideoTitle(title);
843+
if (validTitle) {
844+
document.title = "Duck Player - " + validTitle;
838845
}
839846
});
840847
});

build/windows/contentScope.js

Lines changed: 6153 additions & 8856 deletions
Large diffs are not rendered by default.

build/windows/pages/duckplayer/js/index.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
__publicField(this, "config");
1919
this.messagingContext = messagingContext;
2020
this.config = config;
21+
this.globals = {
22+
window,
23+
JSONparse: window.JSON.parse,
24+
JSONstringify: window.JSON.stringify,
25+
Promise: window.Promise,
26+
Error: window.Error,
27+
String: window.String
28+
};
2129
for (const [methodName, fn] of Object.entries(this.config.methods)) {
2230
if (typeof fn !== "function") {
2331
throw new Error("cannot create WindowsMessagingTransport, missing the method: " + methodName);
@@ -28,7 +36,8 @@
2836
* @param {import('../index.js').NotificationMessage} msg
2937
*/
3038
notify(msg) {
31-
const notification = WindowsNotification.fromNotification(msg);
39+
const data = this.globals.JSONparse(this.globals.JSONstringify(msg.params || {}));
40+
const notification = WindowsNotification.fromNotification(msg, data);
3241
this.config.methods.postMessage(notification);
3342
}
3443
/**
@@ -37,31 +46,32 @@
3746
* @return {Promise<any>}
3847
*/
3948
request(msg, opts = {}) {
40-
const outgoing = WindowsRequestMessage.fromRequest(msg);
49+
const data = this.globals.JSONparse(this.globals.JSONstringify(msg.params || {}));
50+
const outgoing = WindowsRequestMessage.fromRequest(msg, data);
4151
this.config.methods.postMessage(outgoing);
4252
const comparator = (eventData) => {
4353
return eventData.featureName === msg.featureName && eventData.context === msg.context && eventData.id === msg.id;
4454
};
45-
function isMessageResponse(data) {
46-
if ("result" in data)
55+
function isMessageResponse(data2) {
56+
if ("result" in data2)
4757
return true;
48-
if ("error" in data)
58+
if ("error" in data2)
4959
return true;
5060
return false;
5161
}
52-
return new Promise((resolve, reject) => {
62+
return new this.globals.Promise((resolve, reject) => {
5363
try {
5464
this._subscribe(comparator, opts, (value, unsubscribe) => {
5565
unsubscribe();
5666
if (!isMessageResponse(value)) {
5767
console.warn("unknown response type", value);
58-
return reject(new Error("unknown response"));
68+
return reject(new this.globals.Error("unknown response"));
5969
}
6070
if (value.result) {
6171
return resolve(value.result);
6272
}
63-
const message = String(value.error?.message || "unknown error");
64-
reject(new Error(message));
73+
const message = this.globals.String(value.error?.message || "unknown error");
74+
reject(new this.globals.Error(message));
6575
});
6676
} catch (e) {
6777
reject(e);
@@ -158,9 +168,9 @@
158168
* @param {NotificationMessage} notification
159169
* @returns {WindowsNotification}
160170
*/
161-
static fromNotification(notification) {
171+
static fromNotification(notification, data) {
162172
const output = {
163-
Data: JSON.parse(JSON.stringify(notification.params || {})),
173+
Data: data,
164174
Feature: notification.context,
165175
SubFeatureName: notification.featureName,
166176
Name: notification.method
@@ -188,11 +198,12 @@
188198
/**
189199
* Helper to convert a {@link RequestMessage} to a format that Windows can support
190200
* @param {RequestMessage} msg
201+
* @param {Record<string, any>} data
191202
* @returns {WindowsRequestMessage}
192203
*/
193-
static fromRequest(msg) {
204+
static fromRequest(msg, data) {
194205
const output = {
195-
Data: JSON.parse(JSON.stringify(msg.params || {})),
206+
Data: data,
196207
Feature: msg.context,
197208
SubFeatureName: msg.featureName,
198209
Name: msg.method,
@@ -826,15 +837,11 @@
826837
* Sets the tab title to the title of the video once the video title has loaded.
827838
*/
828839
setTabTitle: () => {
829-
let hasGottenValidVideoTitle = false;
830840
VideoPlayer.onIframeLoaded(() => {
831841
VideoPlayer.onIframeTitleChange((title) => {
832-
if (!hasGottenValidVideoTitle) {
833-
const validTitle = VideoPlayer.getValidVideoTitle(title);
834-
if (validTitle) {
835-
document.title = "Duck Player - " + validTitle;
836-
hasGottenValidVideoTitle = true;
837-
}
842+
const validTitle = VideoPlayer.getValidVideoTitle(title);
843+
if (validTitle) {
844+
document.title = "Duck Player - " + validTitle;
838845
}
839846
});
840847
});

inject/android.js

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
* @module Android integration
33
* @category Content Scope Scripts Integrations
44
*/
5-
import { load, init } from '../src/content-scope-features.js'
5+
import { load, init, update } from '../src/content-scope-features.js'
66
import { processConfig, isGloballyDisabled } from './../src/utils'
77

8+
const allowedMessages = [
9+
'getClickToLoadState',
10+
'getYouTubeVideoDetails',
11+
'openShareFeedbackPage',
12+
'setYoutubePreviewsEnabled',
13+
'unblockClickToLoadContent',
14+
'updateYouTubeCTLAddedFlag'
15+
]
16+
817
function initCode () {
918
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
1019
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)
@@ -16,10 +25,53 @@ function initCode () {
1625
platform: processedConfig.platform
1726
})
1827

28+
const messageSecret = processedConfig.messageSecret
29+
// Receives messages from the platform
30+
const messageCallback = processedConfig.messageCallback
31+
// Sends messages to the platform
32+
const messageInterface = processedConfig.messageInterface
33+
34+
const wrappedUpdate = ((providedSecret, ...args) => {
35+
if (providedSecret === messageSecret) {
36+
update(...args)
37+
}
38+
// eslint-disable-next-line no-extra-bind
39+
}).bind(this)
40+
41+
Object.defineProperty(window, messageCallback, {
42+
value: wrappedUpdate
43+
})
44+
45+
let sendMessageToAndroid
46+
if (Object.prototype.hasOwnProperty.call(window, messageInterface)) {
47+
// @ts-expect-error - Defined on the platform using WebView.addJavascriptInterface()
48+
sendMessageToAndroid = window[messageInterface].process.bind(window[messageInterface])
49+
delete window[messageInterface]
50+
} else {
51+
sendMessageToAndroid = () => { console.error('Android messaging interface not available') }
52+
}
53+
1954
init(processedConfig)
2055

21-
// Not supported:
22-
// update(message)
56+
window.addEventListener('sendMessageProxy' + messageSecret, event => {
57+
event.stopImmediatePropagation()
58+
59+
if (!(event instanceof CustomEvent) || !event?.detail) {
60+
return console.warn('no details in sendMessage proxy', event)
61+
}
62+
63+
const messageType = event.detail?.messageType
64+
if (!allowedMessages.includes(messageType)) {
65+
return console.warn('Ignoring invalid sendMessage messageType', messageType)
66+
}
67+
68+
const message = {
69+
type: messageType,
70+
options: event.detail?.options
71+
}
72+
const stringifiedArgs = JSON.stringify(message)
73+
sendMessageToAndroid(stringifiedArgs, messageSecret)
74+
})
2375
}
2476

2577
initCode()

integration-test/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
'**/*.js',
66
'!test-pages/**/*.js',
77
'!pages/**/*.js',
8+
'!playwright/**/*.js',
89
'!extension/**/*.js'
910
],
1011
random: false

0 commit comments

Comments
 (0)