Skip to content

Commit

Permalink
Fix script-overload testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston committed Sep 5, 2023
1 parent 3823ad6 commit ef18595
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/features/runtime-checks/script-overload.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,16 @@ export function wrapScriptCodeOverload (code, config) {
// Ensure globalThis === window
const globalThis = window
`
// Hack to use default capture instead of rollups replaced variable names.
// This is covered by testing so should break if rollup is changed.
const proxyString = constructProxy.toString().replaceAll('Object$1', 'Object').replaceAll('Reflect$1', 'Reflect')
return removeIndent(`(function (parentScope) {
/**
* DuckDuckGo Runtime Checks injected code.
* If you're reading this, you're probably trying to debug a site that is breaking due to our runtime checks.
* Please raise an issues on our GitHub repo: https://github.com/duckduckgo/content-scope-scripts/
*/
${constructProxy.toString()}
${proxyString}
${prepend}
${getContextId.toString()}
Expand Down
10 changes: 5 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ export function hasThirdPartyOrigin (scriptOrigins) {
export function getTabHostname () {
let framingOrigin = null
try {
// @ts-expect-error - globalThis.top is possibly 'null' here
framingOrigin = globalThis.top.location.href
// @ts-expect-error - globalObj.top is possibly 'null' here
framingOrigin = globalObj.top.location.href
} catch {
framingOrigin = globalThis.document.referrer
framingOrigin = globalObj.document.referrer
}

// Not supported in Firefox
if ('ancestorOrigins' in globalThis.location && globalThis.location.ancestorOrigins.length) {
if ('ancestorOrigins' in globalObj.location && globalObj.location.ancestorOrigins.length) {
// ancestorOrigins is reverse order, with the last item being the top frame
framingOrigin = globalThis.location.ancestorOrigins.item(globalThis.location.ancestorOrigins.length - 1)
framingOrigin = globalObj.location.ancestorOrigins.item(globalObj.location.ancestorOrigins.length - 1)
}

try {
Expand Down

0 comments on commit ef18595

Please sign in to comment.