Skip to content

Commit 31012cf

Browse files
Add proxy debugging and runtimeChecks interrogation debug messages (#440)
* Add proxy debugging and runtimeChecks interrogation debug messages * Add multiplier for windows line endings
1 parent 6b90921 commit 31012cf

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/features/runtime-checks.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global TrustedScriptURL, TrustedScript */
22

33
import ContentFeature from '../content-feature.js'
4-
import { DDGProxy, getStackTraceOrigins, getStack, matchHostname, injectGlobalStyles, createStyleElement } from '../utils.js'
4+
import { DDGProxy, getStackTraceOrigins, getStack, matchHostname, injectGlobalStyles, createStyleElement, postDebugMessage } from '../utils.js'
55
import { wrapScriptCodeOverload } from './runtime-checks/script-overload.js'
66

77
let stackDomains = []
@@ -351,19 +351,35 @@ function shouldInterrogate (tagName) {
351351
return false
352352
}
353353
if (matchAllStackDomains) {
354+
isInterrogatingDebugMessage('matchedAllStackDomain')
354355
return true
355356
}
356357
if (taintCheck && document.currentScript?.[taintSymbol]) {
358+
isInterrogatingDebugMessage('taintCheck')
357359
return true
358360
}
359361
const stack = getStack()
360362
const scriptOrigins = [...getStackTraceOrigins(stack)]
361-
const isInterestingHost = scriptOrigins.some(origin => {
363+
const interestingHost = scriptOrigins.find(origin => {
362364
return stackDomains.some(rule => matchHostname(origin, rule.domain))
363365
})
366+
const isInterestingHost = !!interestingHost
367+
if (isInterestingHost) {
368+
isInterrogatingDebugMessage('matchedStackDomain', interestingHost, stack, scriptOrigins)
369+
}
364370
return isInterestingHost
365371
}
366372

373+
function isInterrogatingDebugMessage (matchType, matchedStackDomain, stack, scriptOrigins) {
374+
postDebugMessage('runtimeChecks', {
375+
documentUrl: document.location.href,
376+
matchedStackDomain,
377+
matchType,
378+
scriptOrigins,
379+
stack
380+
})
381+
}
382+
367383
function overrideCreateElement () {
368384
const proxy = new DDGProxy(featureName, Document.prototype, 'createElement', {
369385
apply (fn, scope, args) {

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ export class DDGProxy {
385385
const isExempt = shouldExemptMethod(this.camelFeatureName)
386386
if (debug) {
387387
postDebugMessage(this.camelFeatureName, {
388+
isProxy: true,
388389
action: isExempt ? 'ignore' : 'restrict',
389390
kind: this.property,
390391
documentUrl: document.location.href,

unit-test/verify-artifacts.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import { cwd } from '../scripts/script-utils.js'
66
const ROOT = join(cwd(import.meta.url), '..')
77
const BUILD = join(ROOT, 'build')
88
const APPLE_BUILD = join(ROOT, 'Sources/ContentScopeScripts/dist')
9-
const CSS_OUTPUT_SIZE = 560000
9+
let CSS_OUTPUT_SIZE = 560000
1010
const CSS_OUTPUT_SIZE_CHROME = CSS_OUTPUT_SIZE * 1.45 // 45% larger for Chrome MV2 due to base64 encoding
11+
if (process.platform === 'win32') {
12+
CSS_OUTPUT_SIZE = CSS_OUTPUT_SIZE * 1.1 // 10% larger for Windows due to line endings
13+
}
1114

1215
const checks = {
1316
android: [

0 commit comments

Comments
 (0)