Skip to content

Commit 52cbbf9

Browse files
Fix missing header insertion point (#337)
1 parent c118c93 commit 52cbbf9

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/content-scope-features.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* global mozProxies */
2-
import { initStringExemptionLists, isFeatureBroken, registerMessageSecret } from './utils'
2+
import { initStringExemptionLists, isFeatureBroken, registerMessageSecret, getInjectionElement } from './utils'
33
import { featureNames } from './features'
44
// @ts-expect-error Special glob import for injected features see scripts/utils/build.js
55
import injectedFeaturesCode from 'ddg:runtimeInjects'
@@ -70,7 +70,7 @@ async function injectFeatures (args) {
7070
${codeFeatures.join('\n')}
7171
})()`
7272
script.src = 'data:text/javascript;base64,' + btoa(code)
73-
document.head.appendChild(script)
73+
getInjectionElement().appendChild(script)
7474
script.remove()
7575
}
7676

src/features/element-hiding.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isBeingFramed, getFeatureSetting, matchHostname, DDGProxy, DDGReflect } from '../utils'
1+
import { isBeingFramed, getFeatureSetting, matchHostname, DDGProxy, DDGReflect, getInjectionElement } from '../utils'
22

33
let adLabelStrings = []
44
const parser = new DOMParser()
@@ -227,7 +227,7 @@ function extractTimeoutRules (rules) {
227227
}
228228

229229
/**
230-
* Create styletag for strict hide rules and append it to document head
230+
* Create styletag for strict hide rules and append it to the document
231231
* @param {Object[]} rules
232232
* @param {string} rules[].selector
233233
* @param {string} rules[].type
@@ -249,7 +249,7 @@ function injectStyleTag (rules) {
249249
styleTagContents = styleTagContents.concat('{display:none!important;min-height:0!important;height:0!important;}')
250250
styleTag.href = 'data:text/css,' + encodeURIComponent(styleTagContents)
251251

252-
document.head.appendChild(styleTag)
252+
getInjectionElement().appendChild(styleTag)
253253
}
254254

255255
/**

src/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ export function registerMessageSecret (secret) {
1313
messageSecret = secret
1414
}
1515

16+
/**
17+
* @returns {HTMLElement} the element to inject the script into
18+
*/
19+
export function getInjectionElement () {
20+
return document.head || document.documentElement
21+
}
22+
1623
/**
1724
* Used for testing to override the globals used within this file.
1825
* @param {window} globalObjIn

0 commit comments

Comments
 (0)