Currently, many JavaScript evaluations call methods in __pulsar_utils__, such as __pulsar_utils__.check(selector). The __pulsar_utils__ object is injected using CDP's protocol addScriptToEvaluateOnNewDocument.
To modernize and make these evaluations safer and more maintainable, we propose migrating to Immediately Invoked Function Expressions (IIFE) to replace direct __pulsar_utils__ injection.
Migration Plan
- Extract Method Code at Runtime: In Kotlin code, extract the source code for each
__pulsar_utils__ method at runtime.
- Dynamic IIFE Evaluation: On encountering a call to
__pulsar_utils__.check(selector) (or other methods), locate the corresponding method's code, wrap it as an IIFE, and evaluate it on demand.
This approach provides better encapsulation and avoids potential naming collisions or pollution of the global scope.
Acceptance Criteria:
- Each usage of
__pulsar_utils__ in JS evaluations is safely migrated to an IIFE approach.
- Extraction and dynamic wrapping is handled within the Kotlin code base.
- Old injection of
__pulsar_utils__ is removed.
- Existing functionality remains unaffected and tests remain green.
Example (before):
__pulsar_utils__.check(selector)
Example (after, conceptual):
((params) => { /* extracted check code */ })(selector)
Currently, many JavaScript evaluations call methods in
__pulsar_utils__, such as__pulsar_utils__.check(selector). The__pulsar_utils__object is injected using CDP's protocoladdScriptToEvaluateOnNewDocument.To modernize and make these evaluations safer and more maintainable, we propose migrating to Immediately Invoked Function Expressions (IIFE) to replace direct
__pulsar_utils__injection.Migration Plan
__pulsar_utils__method at runtime.__pulsar_utils__.check(selector)(or other methods), locate the corresponding method's code, wrap it as an IIFE, and evaluate it on demand.This approach provides better encapsulation and avoids potential naming collisions or pollution of the global scope.
Acceptance Criteria:
__pulsar_utils__in JS evaluations is safely migrated to an IIFE approach.__pulsar_utils__is removed.Example (before):
Example (after, conceptual):