Skip to content

Commit ddc9aef

Browse files
Release build 4.54.0 [ci release]
1 parent 27163de commit ddc9aef

File tree

12 files changed

+335
-109
lines changed

12 files changed

+335
-109
lines changed

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@
19901990
__privateAdd(this, _messaging, void 0);
19911991
/** @type {boolean} */
19921992
__privateAdd(this, _isDebugFlagSet, false);
1993-
/** @type {{ debug?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
1993+
/** @type {{ debug?: boolean, desktopModeEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
19941994
__privateAdd(this, _args, void 0);
19951995
this.name = featureName;
19961996
__privateSet(this, _args, null);
@@ -1999,6 +1999,9 @@
19991999
get isDebug() {
20002000
return __privateGet(this, _args)?.debug || false;
20012001
}
2002+
get desktopModeEnabled() {
2003+
return __privateGet(this, _args)?.desktopModeEnabled || false;
2004+
}
20022005
/**
20032006
* @param {import('./utils').Platform} platform
20042007
*/
@@ -2733,17 +2736,42 @@
27332736
};
27342737
}
27352738
viewportWidthFix() {
2736-
const viewportTag = document.querySelector("meta[name=viewport]");
2737-
if (!viewportTag)
2738-
return;
2739-
const viewportContent = viewportTag.getAttribute("content");
2740-
if (!viewportContent)
2741-
return;
2742-
const viewportContentParts = viewportContent.split(",");
2743-
const widthPart = viewportContentParts.find((part) => part.includes("width"));
2744-
if (widthPart)
2745-
return;
2746-
viewportTag.setAttribute("content", `${viewportContent},width=device-width`);
2739+
const viewportTags = document.querySelectorAll("meta[name=viewport]");
2740+
let viewportTag = viewportTags.length === 0 ? null : viewportTags[viewportTags.length - 1];
2741+
const viewportContent = viewportTag?.getAttribute("content") || "";
2742+
const viewportContentParts = viewportContent ? viewportContent.split(/,|;/) : [];
2743+
const parsedViewportContent = viewportContentParts.map((part) => {
2744+
const [key, value] = part.split("=").map((p) => p.trim().toLowerCase());
2745+
return [key, value];
2746+
});
2747+
if (!viewportTag || this.desktopModeEnabled) {
2748+
const viewportTagExists = Boolean(viewportTag);
2749+
if (!viewportTag) {
2750+
viewportTag = document.createElement("meta");
2751+
viewportTag.setAttribute("name", "viewport");
2752+
}
2753+
const forcedWidth = screen.width >= 1280 ? 1280 : 980;
2754+
const forcedInitialScale = (screen.width / forcedWidth).toFixed(3);
2755+
let newContent = `width=${forcedWidth}, initial-scale=${forcedInitialScale}`;
2756+
parsedViewportContent.forEach(([key], idx) => {
2757+
if (!["width", "initial-scale", "user-scalable"].includes(key)) {
2758+
newContent = newContent.concat(`,${viewportContentParts[idx]}`);
2759+
}
2760+
});
2761+
viewportTag.setAttribute("content", newContent);
2762+
if (!viewportTagExists) {
2763+
document.head.appendChild(viewportTag);
2764+
}
2765+
} else {
2766+
const widthPart = parsedViewportContent.find(([key]) => key === "width");
2767+
const initialScalePart = parsedViewportContent.find(([key]) => key === "initial-scale");
2768+
if (!widthPart && initialScalePart) {
2769+
const parsedInitialScale = parseFloat(initialScalePart[1]);
2770+
if (parsedInitialScale !== 1) {
2771+
viewportTag.setAttribute("content", `width=device-width, ${viewportContent}`);
2772+
}
2773+
}
2774+
}
27472775
}
27482776
}
27492777
_activeShareRequest = new WeakMap();

Sources/ContentScopeScripts/dist/contentScopeIsolated.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@
26092609
/** @type {boolean} */
26102610
#isDebugFlagSet = false
26112611

2612-
/** @type {{ debug?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
2612+
/** @type {{ debug?: boolean, desktopModeEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
26132613
#args
26142614

26152615
constructor (featureName) {
@@ -2622,6 +2622,10 @@
26222622
return this.#args?.debug || false
26232623
}
26242624

2625+
get desktopModeEnabled () {
2626+
return this.#args?.desktopModeEnabled || false
2627+
}
2628+
26252629
/**
26262630
* @param {import('./utils').Platform} platform
26272631
*/

build/android/contentScope.js

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,7 @@
29642964
/** @type {boolean} */
29652965
#isDebugFlagSet = false
29662966

2967-
/** @type {{ debug?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
2967+
/** @type {{ debug?: boolean, desktopModeEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
29682968
#args
29692969

29702970
constructor (featureName) {
@@ -2977,6 +2977,10 @@
29772977
return this.#args?.debug || false
29782978
}
29792979

2980+
get desktopModeEnabled () {
2981+
return this.#args?.desktopModeEnabled || false
2982+
}
2983+
29802984
/**
29812985
* @param {import('./utils').Platform} platform
29822986
*/
@@ -7899,15 +7903,48 @@
78997903
}
79007904

79017905
viewportWidthFix () {
7902-
const viewportTag = document.querySelector('meta[name=viewport]');
7903-
if (!viewportTag) return
7904-
const viewportContent = viewportTag.getAttribute('content');
7905-
if (!viewportContent) return
7906-
const viewportContentParts = viewportContent.split(',');
7907-
const widthPart = viewportContentParts.find((part) => part.includes('width'));
7908-
// If we already have a width, don't add one
7909-
if (widthPart) return
7910-
viewportTag.setAttribute('content', `${viewportContent},width=device-width`);
7906+
const viewportTags = document.querySelectorAll('meta[name=viewport]');
7907+
// Chrome respects only the last viewport tag
7908+
let viewportTag = viewportTags.length === 0 ? null : viewportTags[viewportTags.length - 1];
7909+
const viewportContent = viewportTag?.getAttribute('content') || '';
7910+
const viewportContentParts = viewportContent ? viewportContent.split(/,|;/) : [];
7911+
const parsedViewportContent = viewportContentParts.map((part) => {
7912+
const [key, value] = part.split('=').map(p => p.trim().toLowerCase());
7913+
return [key, value]
7914+
});
7915+
if (!viewportTag || this.desktopModeEnabled) {
7916+
// force wide viewport width
7917+
const viewportTagExists = Boolean(viewportTag);
7918+
if (!viewportTag) {
7919+
viewportTag = document.createElement('meta');
7920+
viewportTag.setAttribute('name', 'viewport');
7921+
}
7922+
const forcedWidth = screen.width >= 1280 ? 1280 : 980;
7923+
// Race condition: depending on the loading state of the page, initial scale may or may not be respected, so the page may look zoomed-in after applying this hack.
7924+
// Usually this is just an annoyance, but it may be a bigger issue if user-scalable=no is set, so we remove it too.
7925+
const forcedInitialScale = (screen.width / forcedWidth).toFixed(3);
7926+
let newContent = `width=${forcedWidth}, initial-scale=${forcedInitialScale}`;
7927+
parsedViewportContent.forEach(([key], idx) => {
7928+
if (!['width', 'initial-scale', 'user-scalable'].includes(key)) {
7929+
newContent = newContent.concat(`,${viewportContentParts[idx]}`); // reuse the original values, not the parsed ones
7930+
}
7931+
});
7932+
viewportTag.setAttribute('content', newContent);
7933+
if (!viewportTagExists) {
7934+
document.head.appendChild(viewportTag);
7935+
}
7936+
} else { // mobile mode with a viewport tag
7937+
// fix an edge case where WebView forces the wide viewport
7938+
const widthPart = parsedViewportContent.find(([key]) => key === 'width');
7939+
const initialScalePart = parsedViewportContent.find(([key]) => key === 'initial-scale');
7940+
if (!widthPart && initialScalePart) {
7941+
// Chromium accepts float values for initial-scale
7942+
const parsedInitialScale = parseFloat(initialScalePart[1]);
7943+
if (parsedInitialScale !== 1) {
7944+
viewportTag.setAttribute('content', `width=device-width, ${viewportContent}`);
7945+
}
7946+
}
7947+
}
79117948
}
79127949
}
79137950

build/chrome-mv3/inject.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,7 @@
29762976
/** @type {boolean} */
29772977
#isDebugFlagSet = false
29782978

2979-
/** @type {{ debug?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
2979+
/** @type {{ debug?: boolean, desktopModeEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
29802980
#args
29812981

29822982
constructor (featureName) {
@@ -2989,6 +2989,10 @@
29892989
return this.#args?.debug || false
29902990
}
29912991

2992+
get desktopModeEnabled () {
2993+
return this.#args?.desktopModeEnabled || false
2994+
}
2995+
29922996
/**
29932997
* @param {import('./utils').Platform} platform
29942998
*/

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: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@
29182918
/** @type {boolean} */
29192919
#isDebugFlagSet = false
29202920

2921-
/** @type {{ debug?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
2921+
/** @type {{ debug?: boolean, desktopModeEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
29222922
#args
29232923

29242924
constructor (featureName) {
@@ -2931,6 +2931,10 @@
29312931
return this.#args?.debug || false
29322932
}
29332933

2934+
get desktopModeEnabled () {
2935+
return this.#args?.desktopModeEnabled || false
2936+
}
2937+
29342938
/**
29352939
* @param {import('./utils').Platform} platform
29362940
*/
@@ -14068,15 +14072,48 @@
1406814072
}
1406914073

1407014074
viewportWidthFix () {
14071-
const viewportTag = document.querySelector('meta[name=viewport]');
14072-
if (!viewportTag) return
14073-
const viewportContent = viewportTag.getAttribute('content');
14074-
if (!viewportContent) return
14075-
const viewportContentParts = viewportContent.split(',');
14076-
const widthPart = viewportContentParts.find((part) => part.includes('width'));
14077-
// If we already have a width, don't add one
14078-
if (widthPart) return
14079-
viewportTag.setAttribute('content', `${viewportContent},width=device-width`);
14075+
const viewportTags = document.querySelectorAll('meta[name=viewport]');
14076+
// Chrome respects only the last viewport tag
14077+
let viewportTag = viewportTags.length === 0 ? null : viewportTags[viewportTags.length - 1];
14078+
const viewportContent = viewportTag?.getAttribute('content') || '';
14079+
const viewportContentParts = viewportContent ? viewportContent.split(/,|;/) : [];
14080+
const parsedViewportContent = viewportContentParts.map((part) => {
14081+
const [key, value] = part.split('=').map(p => p.trim().toLowerCase());
14082+
return [key, value]
14083+
});
14084+
if (!viewportTag || this.desktopModeEnabled) {
14085+
// force wide viewport width
14086+
const viewportTagExists = Boolean(viewportTag);
14087+
if (!viewportTag) {
14088+
viewportTag = document.createElement('meta');
14089+
viewportTag.setAttribute('name', 'viewport');
14090+
}
14091+
const forcedWidth = screen.width >= 1280 ? 1280 : 980;
14092+
// Race condition: depending on the loading state of the page, initial scale may or may not be respected, so the page may look zoomed-in after applying this hack.
14093+
// Usually this is just an annoyance, but it may be a bigger issue if user-scalable=no is set, so we remove it too.
14094+
const forcedInitialScale = (screen.width / forcedWidth).toFixed(3);
14095+
let newContent = `width=${forcedWidth}, initial-scale=${forcedInitialScale}`;
14096+
parsedViewportContent.forEach(([key], idx) => {
14097+
if (!['width', 'initial-scale', 'user-scalable'].includes(key)) {
14098+
newContent = newContent.concat(`,${viewportContentParts[idx]}`); // reuse the original values, not the parsed ones
14099+
}
14100+
});
14101+
viewportTag.setAttribute('content', newContent);
14102+
if (!viewportTagExists) {
14103+
document.head.appendChild(viewportTag);
14104+
}
14105+
} else { // mobile mode with a viewport tag
14106+
// fix an edge case where WebView forces the wide viewport
14107+
const widthPart = parsedViewportContent.find(([key]) => key === 'width');
14108+
const initialScalePart = parsedViewportContent.find(([key]) => key === 'initial-scale');
14109+
if (!widthPart && initialScalePart) {
14110+
// Chromium accepts float values for initial-scale
14111+
const parsedInitialScale = parseFloat(initialScalePart[1]);
14112+
if (parsedInitialScale !== 1) {
14113+
viewportTag.setAttribute('content', `width=device-width, ${viewportContent}`);
14114+
}
14115+
}
14116+
}
1408014117
}
1408114118
}
1408214119

build/firefox/inject.js

Lines changed: 6 additions & 2 deletions
Large diffs are not rendered by default.

build/integration/contentScope.js

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@
29182918
/** @type {boolean} */
29192919
#isDebugFlagSet = false
29202920

2921-
/** @type {{ debug?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
2921+
/** @type {{ debug?: boolean, desktopModeEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
29222922
#args
29232923

29242924
constructor (featureName) {
@@ -2931,6 +2931,10 @@
29312931
return this.#args?.debug || false
29322932
}
29332933

2934+
get desktopModeEnabled () {
2935+
return this.#args?.desktopModeEnabled || false
2936+
}
2937+
29342938
/**
29352939
* @param {import('./utils').Platform} platform
29362940
*/
@@ -14068,15 +14072,48 @@
1406814072
}
1406914073

1407014074
viewportWidthFix () {
14071-
const viewportTag = document.querySelector('meta[name=viewport]');
14072-
if (!viewportTag) return
14073-
const viewportContent = viewportTag.getAttribute('content');
14074-
if (!viewportContent) return
14075-
const viewportContentParts = viewportContent.split(',');
14076-
const widthPart = viewportContentParts.find((part) => part.includes('width'));
14077-
// If we already have a width, don't add one
14078-
if (widthPart) return
14079-
viewportTag.setAttribute('content', `${viewportContent},width=device-width`);
14075+
const viewportTags = document.querySelectorAll('meta[name=viewport]');
14076+
// Chrome respects only the last viewport tag
14077+
let viewportTag = viewportTags.length === 0 ? null : viewportTags[viewportTags.length - 1];
14078+
const viewportContent = viewportTag?.getAttribute('content') || '';
14079+
const viewportContentParts = viewportContent ? viewportContent.split(/,|;/) : [];
14080+
const parsedViewportContent = viewportContentParts.map((part) => {
14081+
const [key, value] = part.split('=').map(p => p.trim().toLowerCase());
14082+
return [key, value]
14083+
});
14084+
if (!viewportTag || this.desktopModeEnabled) {
14085+
// force wide viewport width
14086+
const viewportTagExists = Boolean(viewportTag);
14087+
if (!viewportTag) {
14088+
viewportTag = document.createElement('meta');
14089+
viewportTag.setAttribute('name', 'viewport');
14090+
}
14091+
const forcedWidth = screen.width >= 1280 ? 1280 : 980;
14092+
// Race condition: depending on the loading state of the page, initial scale may or may not be respected, so the page may look zoomed-in after applying this hack.
14093+
// Usually this is just an annoyance, but it may be a bigger issue if user-scalable=no is set, so we remove it too.
14094+
const forcedInitialScale = (screen.width / forcedWidth).toFixed(3);
14095+
let newContent = `width=${forcedWidth}, initial-scale=${forcedInitialScale}`;
14096+
parsedViewportContent.forEach(([key], idx) => {
14097+
if (!['width', 'initial-scale', 'user-scalable'].includes(key)) {
14098+
newContent = newContent.concat(`,${viewportContentParts[idx]}`); // reuse the original values, not the parsed ones
14099+
}
14100+
});
14101+
viewportTag.setAttribute('content', newContent);
14102+
if (!viewportTagExists) {
14103+
document.head.appendChild(viewportTag);
14104+
}
14105+
} else { // mobile mode with a viewport tag
14106+
// fix an edge case where WebView forces the wide viewport
14107+
const widthPart = parsedViewportContent.find(([key]) => key === 'width');
14108+
const initialScalePart = parsedViewportContent.find(([key]) => key === 'initial-scale');
14109+
if (!widthPart && initialScalePart) {
14110+
// Chromium accepts float values for initial-scale
14111+
const parsedInitialScale = parseFloat(initialScalePart[1]);
14112+
if (parsedInitialScale !== 1) {
14113+
viewportTag.setAttribute('content', `width=device-width, ${viewportContent}`);
14114+
}
14115+
}
14116+
}
1408014117
}
1408114118
}
1408214119

build/windows/contentScope.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3035,7 +3035,7 @@
30353035
/** @type {boolean} */
30363036
#isDebugFlagSet = false
30373037

3038-
/** @type {{ debug?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
3038+
/** @type {{ debug?: boolean, desktopModeEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: AssetConfig | undefined, site: Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null} */
30393039
#args
30403040

30413041
constructor (featureName) {
@@ -3048,6 +3048,10 @@
30483048
return this.#args?.debug || false
30493049
}
30503050

3051+
get desktopModeEnabled () {
3052+
return this.#args?.desktopModeEnabled || false
3053+
}
3054+
30513055
/**
30523056
* @param {import('./utils').Platform} platform
30533057
*/

0 commit comments

Comments
 (0)