ScriptInjection constructor

ScriptInjection({
  1. JSAny? func,
  2. List<Object>? args,
  3. JSAny? function,
  4. List<String>? files,
  5. required InjectionTarget target,
  6. ExecutionWorld? world,
  7. bool? injectImmediately,
})

Implementation

ScriptInjection({
  /// A JavaScript function to inject. This function will be serialized, and
  /// then deserialized for injection. This means that any bound parameters
  /// and execution context will be lost.
  /// Exactly one of `files` or `func` must be
  /// specified.
  JSAny? func,

  /// The arguments to pass to the provided function. This is only valid if
  /// the `func` parameter is specified. These arguments must be
  /// JSON-serializable.
  List<Object>? args,

  /// We used to call the injected function `function`, but this is
  /// incompatible with JavaScript's object declaration shorthand (see
  /// https://crbug.com/1166438). We leave this silently in for backwards
  /// compatibility.
  /// TODO(devlin): Remove this in M95.
  JSAny? function,

  /// The path of the JS or CSS files to inject, relative to the extension's
  /// root directory.
  /// Exactly one of `files` or `func` must be
  /// specified.
  List<String>? files,

  /// Details specifying the target into which to inject the script.
  required InjectionTarget target,

  /// The JavaScript "world" to run the script in. Defaults to
  /// `ISOLATED`.
  ExecutionWorld? world,

  /// Whether the injection should be triggered in the target as soon as
  /// possible. Note that this is not a guarantee that injection will occur
  /// prior to page load, as the page may have already loaded by the time the
  /// script reaches the target.
  bool? injectImmediately,
}) : _wrapped = $js.ScriptInjection(
        func: func,
        args: args?.toJSArray((e) => e.jsify()!),
        function: function,
        files: files?.toJSArray((e) => e),
        target: target.toJS,
        world: world?.toJS,
        injectImmediately: injectImmediately,
      );