@@ -16,6 +16,13 @@ class ExecutionContext {
16
16
17
17
/** @type {number|undefined } */
18
18
this . _executionContextId = undefined ;
19
+ /**
20
+ * Marks how many execution context ids have been created, for purposes of having a unique
21
+ * value (that doesn't expose the actual execution context id) to
22
+ * use for __lighthouseExecutionContextUniqueIdentifier.
23
+ * @type {number }
24
+ */
25
+ this . _executionContextIdentifiersCreated = 0 ;
19
26
20
27
// We use isolated execution contexts for `evaluateAsync` that can be destroyed through navigation
21
28
// and other page actions. Cleanup our relevant bookkeeping as we see those events.
@@ -64,10 +71,10 @@ class ExecutionContext {
64
71
} ) ;
65
72
66
73
this . _executionContextId = isolatedWorldResponse . executionContextId ;
74
+ this . _executionContextIdentifiersCreated ++ ;
67
75
return isolatedWorldResponse . executionContextId ;
68
76
}
69
77
70
-
71
78
/**
72
79
* Evaluate an expression in the given execution context; an undefined contextId implies the main
73
80
* page without isolation.
@@ -82,15 +89,25 @@ class ExecutionContext {
82
89
this . _session . getNextProtocolTimeout ( ) :
83
90
60000 ;
84
91
92
+ // `__lighthouseExecutionContextUniqueIdentifier` is only used by the FullPageScreenshot gatherer.
93
+ // See `getNodeDetails` in page-functions.
94
+ const uniqueExecutionContextIdentifier = contextId === undefined ?
95
+ undefined :
96
+ this . _executionContextIdentifiersCreated ;
97
+
85
98
const evaluationParams = {
86
99
// We need to explicitly wrap the raw expression for several purposes:
87
100
// 1. Ensure that the expression will be a native Promise and not a polyfill/non-Promise.
88
101
// 2. Ensure that errors in the expression are captured by the Promise.
89
102
// 3. Ensure that errors captured in the Promise are converted into plain-old JS Objects
90
103
// so that they can be serialized properly b/c JSON.stringify(new Error('foo')) === '{}'
104
+ //
105
+ // `__lighthouseExecutionContextUniqueIdentifier` is only used by the FullPageScreenshot gatherer.
106
+ // See `getNodeDetails` in page-functions.
91
107
expression : `(function wrapInNativePromise() {
92
108
${ ExecutionContext . _cachedNativesPreamble } ;
93
- globalThis.__lighthouseExecutionContextId = ${ contextId } ;
109
+ globalThis.__lighthouseExecutionContextUniqueIdentifier =
110
+ ${ uniqueExecutionContextIdentifier } ;
94
111
return new Promise(function (resolve) {
95
112
return Promise.resolve()
96
113
.then(_ => ${ expression } )
0 commit comments