Skip to content

Commit 44e1bd9

Browse files
ladamskiladamski@duckduckgo.com
andauthored
MV3 click to load support (#189)
* mv3 messaging support * MV3 enable social tracker * revert package-lock.json * build * handle config response on init * cleanup debug * builds * fix mozilla sendMessage proxy * builds Co-authored-by: ladamski@duckduckgo.com <ladamski@duckduckgo.com>
1 parent ed10de3 commit 44e1bd9

File tree

10 files changed

+57
-78
lines changed

10 files changed

+57
-78
lines changed

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,7 +3188,7 @@
31883188
if (this.replaceSettings.type === 'loginButton') {
31893189
isLogin = true;
31903190
}
3191-
enableSocialTracker(this.entity, isLogin);
3191+
enableSocialTracker({ entity: this.entity, action: 'block-ctl-fb', isLogin });
31923192
const parent = replacementElement.parentNode;
31933193

31943194
// If we allow everything when this element is clicked,
@@ -3506,16 +3506,12 @@
35063506
/*********************************************************
35073507
* Messaging to surrogates & extension
35083508
*********************************************************/
3509-
function enableSocialTracker (entity, isLogin) {
3510-
const message = {
3511-
entity,
3512-
isLogin
3513-
};
3509+
function enableSocialTracker (message) {
35143510
sendMessage('enableSocialTracker', message);
35153511
}
35163512

35173513
function runLogin (entity) {
3518-
enableSocialTracker(entity, true);
3514+
enableSocialTracker(entity);
35193515
window.dispatchEvent(
35203516
createCustomEvent('ddg-ctp-run-login', {
35213517
detail: {
@@ -4236,12 +4232,13 @@
42364232
}
42374233

42384234
function update$1 (args) {
4239-
if (!(args && args.type)) { return }
4235+
const detail = args && args.detail;
4236+
if (!(detail && detail.func)) { return }
42404237

4241-
const fn = updateHandlers[args.type];
4238+
const fn = updateHandlers[detail.func];
42424239
if (typeof fn !== 'function') { return }
42434240

4244-
fn(args.response);
4241+
fn(detail.response);
42454242
}
42464243

42474244
var clickToPlay = /*#__PURE__*/Object.freeze({

build/android/contentScope.js

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/chrome-mv3/inject.js

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/chrome/inject.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/firefox/inject.js

Lines changed: 9 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/integration/contentScope.js

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/windows/contentScope.js

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inject/chrome.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ function init () {
113113
window.addEventListener('sendMessage', (m) => {
114114
const messageType = m.detail.messageType
115115
chrome.runtime.sendMessage(m && m.detail, response => {
116-
const msg = { type: messageType, response }
117-
const stringifiedArgs = JSON.stringify(msg)
116+
const msg = { func: messageType, response }
117+
const stringifiedArgs = JSON.stringify({ detail: msg })
118118
const callRandomUpdateFunction = `
119119
window.${reusableMethodName}('${reusableSecret}', ${stringifiedArgs});
120120
`

inject/mozilla.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function init () {
4141
window.addEventListener('sendMessage', (m) => {
4242
const messageType = m.detail.messageType
4343
chrome.runtime.sendMessage(m && m.detail, response => {
44-
const msg = { type: messageType, response }
45-
contentScopeFeatures.update(msg)
44+
const msg = { func: messageType, response }
45+
contentScopeFeatures.update({ detail: msg })
4646
})
4747
})
4848
}

src/features/click-to-play.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ class DuckWidget {
12431243
if (this.replaceSettings.type === 'loginButton') {
12441244
isLogin = true
12451245
}
1246-
enableSocialTracker(this.entity, isLogin)
1246+
enableSocialTracker({ entity: this.entity, action: 'block-ctl-fb', isLogin })
12471247
const parent = replacementElement.parentNode
12481248

12491249
// If we allow everything when this element is clicked,
@@ -1561,11 +1561,7 @@ async function replaceClickToLoadElements (config, targetElement) {
15611561
/*********************************************************
15621562
* Messaging to surrogates & extension
15631563
*********************************************************/
1564-
function enableSocialTracker (entity, isLogin) {
1565-
const message = {
1566-
entity,
1567-
isLogin
1568-
}
1564+
function enableSocialTracker (message) {
15691565
sendMessage('enableSocialTracker', message)
15701566
}
15711567

@@ -2291,10 +2287,11 @@ export function init (args) {
22912287
}
22922288

22932289
export function update (args) {
2294-
if (!(args && args.type)) { return }
2290+
const detail = args && args.detail
2291+
if (!(detail && detail.func)) { return }
22952292

2296-
const fn = updateHandlers[args.type]
2293+
const fn = updateHandlers[detail.func]
22972294
if (typeof fn !== 'function') { return }
22982295

2299-
fn(args.response)
2296+
fn(detail.response)
23002297
}

0 commit comments

Comments
 (0)