Skip to content

Remove the need for the build replacements for all non chrome platforms #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions inject/android.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* global contentScopeFeatures */
/**
* @module Android integration
* @category Content Scope Scripts Integrations
*/
import { load, init } from '../src/content-scope-features.js'
import { processConfig, isGloballyDisabled } from './../src/utils'

function init () {
function initCode () {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)
if (isGloballyDisabled(processedConfig)) {
return
}

contentScopeFeatures.load({
load({
platform: processedConfig.platform
})

contentScopeFeatures.init(processedConfig)
init(processedConfig)

// Not supported:
// contentScopeFeatures.update(message)
// update(message)
}

init()
initCode()
19 changes: 9 additions & 10 deletions inject/apple.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
/* global contentScopeFeatures */
/**
* @module Apple integration
* @category Content Scope Scripts Integrations
*/

* @module Apple integration
* @category Content Scope Scripts Integrations
*/
import { load, init } from '../src/content-scope-features.js'
import { processConfig, isGloballyDisabled } from './../src/utils'

function init () {
function initCode () {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)
if (isGloballyDisabled(processedConfig)) {
return
}

contentScopeFeatures.load({
load({
platform: processedConfig.platform
})

contentScopeFeatures.init(processedConfig)
init(processedConfig)

// Not supported:
// contentScopeFeatures.update(message)
// update(message)
}

init()
initCode()
15 changes: 7 additions & 8 deletions inject/chrome-mv3.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* global contentScopeFeatures */
/**
* @module Chrome MV3 integration
* @category Content Scope Scripts Integrations
*/

* @module Chrome MV3 integration
* @category Content Scope Scripts Integrations
*/
import { load, init, update } from '../src/content-scope-features.js'
import { isTrackerOrigin } from '../src/trackers'

const secret = (crypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32).toString().replace('0.', '')

contentScopeFeatures.load({
load({
platform: {
name: 'extension'
},
Expand All @@ -24,12 +23,12 @@ window.addEventListener(secret, ({ detail: message }) => {

switch (message.type) {
case 'update':
contentScopeFeatures.update(message)
update(message)
break
case 'register':
if (message.argumentsObject) {
message.argumentsObject.messageSecret = secret
contentScopeFeatures.init(message.argumentsObject)
init(message.argumentsObject)
}
break
}
Expand Down
12 changes: 6 additions & 6 deletions inject/integration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global contentScopeFeatures */
import { load, init } from '../src/content-scope-features.js'
function getTopLevelURL () {
try {
// FROM: https://stackoverflow.com/a/7739035/73479
Expand Down Expand Up @@ -66,19 +66,19 @@ function mergeDeep (target, ...sources) {
return mergeDeep(target, ...sources)
}

async function init () {
async function initCode () {
const topLevelUrl = getTopLevelURL()
const processedConfig = generateConfig()

await contentScopeFeatures.load({
await load({
platform: processedConfig.platform
})

// mark this phase as loaded
setStatus('loaded')

if (!topLevelUrl.searchParams.has('wait-for-init-args')) {
await contentScopeFeatures.init(processedConfig)
await init(processedConfig)
setStatus('initialized')
return
}
Expand All @@ -88,7 +88,7 @@ async function init () {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const merged = mergeDeep(processedConfig, evt.detail)
// init features
await contentScopeFeatures.init(merged)
await init(merged)

// set status to initialized so that tests can resume
setStatus('initialized')
Expand All @@ -103,4 +103,4 @@ function setStatus (status) {
window.__content_scope_status = status
}

init()
initCode()
20 changes: 10 additions & 10 deletions inject/mozilla.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global contentScopeFeatures */
/**
* @module Mozilla integration
* @category Content Scope Scripts Integrations
*/
* @module Mozilla integration
* @category Content Scope Scripts Integrations
*/
import { load, init, update } from '../src/content-scope-features.js'
import { isTrackerOrigin } from '../src/trackers'

const allowedMessages = [
Expand All @@ -20,8 +20,8 @@ function randomString () {
return num.toString().replace('0.', '')
}

function init () {
contentScopeFeatures.load({
function initCode () {
load({
platform: {
name: 'extension'
},
Expand Down Expand Up @@ -53,13 +53,13 @@ function init () {
})
}
message.messageSecret = messageSecret
contentScopeFeatures.init(message)
init(message)
})

chrome.runtime.onMessage.addListener((message) => {
// forward update messages to the embedded script
if (message && message.type === 'update') {
contentScopeFeatures.update(message)
update(message)
}
})

Expand All @@ -82,9 +82,9 @@ function init () {
response
}

contentScopeFeatures.update(message)
update(message)
})
})
}

init()
initCode()
12 changes: 6 additions & 6 deletions inject/windows.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* global contentScopeFeatures */
/**
* @module Windows integration
* @category Content Scope Scripts Integrations
*/
import { load, init } from '../src/content-scope-features.js'
import { processConfig, isGloballyDisabled, windowsSpecificFeatures } from './../src/utils'

function init () {
function initCode () {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$, windowsSpecificFeatures)
if (isGloballyDisabled(processedConfig)) {
return
}

contentScopeFeatures.load({
load({
platform: processedConfig.platform
})

contentScopeFeatures.init(processedConfig)
init(processedConfig)

// Not supported:
// contentScopeFeatures.update(message)
// update(message)
}

init()
initCode()
4 changes: 1 addition & 3 deletions scripts/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ async function init () {
}

async function initOther (injectScriptPath, platformName) {
const replaceString = '/* global contentScopeFeatures */'
const injectScript = await rollupScript(injectScriptPath, `inject${platformName}`)
const contentScope = await rollupScript(contentScopePath, contentScopeName)
const outputScript = injectScript.toString().replace(replaceString, contentScope.toString())
const outputScript = injectScript
console.log(outputScript)
}

Expand Down