Skip to content

Commit c99e9ca

Browse files
committed
AG-44207 add comment inside getScriptletCode
Squashed commit of the following: commit 3b16207 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed Aug 27 00:46:18 2025 -0400 add comment inside getScriptletCode
1 parent 3b61180 commit c99e9ca

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/scriptlets/scriptlets.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ function getScriptletCode(source: Source): string {
131131

132132
const scriptletFunctionString = scriptletFunction.toString();
133133

134+
/**
135+
* `corelibs` (and `test`) environments expect a function definition
136+
* that they will invoke later with their own injection mechanism,
137+
* so we wrap the scriptlet in an anonymous function that accepts parameters — source and args.
138+
*
139+
* `extension` environment need the scriptlet to execute immediately upon injection,
140+
* so we wrap it in an IIFE with the source configuration and arguments passed directly.
141+
*/
134142
const result = source.engine === 'corelibs' || source.engine === 'test'
135143
? wrapInNonameFunc(scriptletFunctionString)
136144
: passSourceAndProps(source, scriptletFunctionString);

0 commit comments

Comments
 (0)