Skip to content

Safe migration from __pulsar_utils__.method() to IIFE in JS evaluations #141

@galaxyeye

Description

@galaxyeye

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

  1. Extract Method Code at Runtime: In Kotlin code, extract the source code for each __pulsar_utils__ method at runtime.
  2. 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)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions