Skip to content

Script Injection (injects)

Overview

injects allows injecting scripts into HTML pages at specific paths. It is designed for minimal adaptation of third-party apps. Requires lzcos 1.5.0+.

Matching Rules

  • If paths is empty: match all paths
  • If paths is not empty: any prefix match is enough
  • If a matched path also matches any prefix in exclude, injection is skipped
  • If prefix_domain is set: only match hosts whose prefix is <prefix>-
  • injects entries run in order; scripts inside each entry also run in order

Script Sources

scripts[].src supports:

  • builtin://name Built-in scripts from lzcinit
  • file:///path Scripts from the app filesystem (usually under /lzcapp/pkg/content/)
  • http(s)://... Remote scripts (recommended for debugging only)

Parameter Injection

scripts[].params is injected as a closure parameter. Access it via __LZC_INJECT_PARAMS__ inside the script.

Example (script side):

js
(() => {
  const params = __LZC_INJECT_PARAMS__ || {};
  const user = params.user || "";
  const password = params.password || "";
  if (user) {
    console.log("user:", user);
  }
})();
(() => {
  const params = __LZC_INJECT_PARAMS__ || {};
  const user = params.user || "";
  const password = params.password || "";
  if (user) {
    console.log("user:", user);
  }
})();

Usage Tips

  • Strongly recommend limiting paths to login pages or specific routes
  • Use exclude for API or static resource paths to avoid accidental injection
  • Remote scripts should be used for debugging only; release builds should use builtin:// or file://
  • If the page has strict CSP, injected scripts may not execute

Built-in Scripts

builtin://hello

Prints a debug message.

Params:

  • message: output content, default hello world

builtin://simple-inject-password

Auto-fills username/password and optionally auto-submits. Recommended only for explicit login paths.

Params (params):

NameTypeDescription
userstringUsername value
passwordstringPassword value
requireUserboolWhether a username field is required. Defaults to true when user is non-empty
allowPasswordOnlyboolAllow password-only fill. Default false
userSelectorstringExplicit selector for username field
passwordSelectorstringExplicit selector for password field
formSelectorstringLimit field search to a specific container
submitSelectorstringExplicit selector for submit button
autoSubmitboolAuto submit after fill. Default true
submitModestringSubmit mode: auto/requestSubmit/click/enter, default auto
retryCountintAuto-submit retry count, default 10
retryIntervalMsintAuto-submit retry interval (ms), default 300
observerTimeoutMsintMutationObserver timeout (ms), default 8000
eventSequencestring or []stringEvent sequence, default input,change,keydown,keyup,blur
keyValuestringKey value used for keyboard events, default a
allowHiddenboolAllow filling hidden fields, default false
allowReadOnlyboolAllow filling read-only fields, default false
onlyFillEmptyboolOnly fill when field is empty, default false
allowNewPasswordboolAllow filling autocomplete=new-password fields, default false
includeShadowDomboolSearch open Shadow DOM, default false
shadowDomMaxDepthintShadow DOM max recursion depth, default 2
preferSameFormboolPrefer username in the same form as password, default true
userKeywordsstring or []stringExtra username keywords
userExcludeKeywordsstring or []stringExtra username exclude keywords
passwordKeywordsstring or []stringExtra password keywords
passwordExcludeKeywordsstring or []stringExtra password exclude keywords
submitKeywordsstring or []stringExtra submit button keywords

Example:

yml
application:
  injects:
    - id: login-autofill
      paths:
        - /login
      scripts:
        - src: builtin://simple-inject-password
          params:
            user: "admin"
            password: "admin123"
            autoSubmit: true
            submitMode: "auto"
            userSelector: "#username"
            passwordSelector: "#password"
            submitKeywords: "login,signin,continue"
application:
  injects:
    - id: login-autofill
      paths:
        - /login
      scripts:
        - src: builtin://simple-inject-password
          params:
            user: "admin"
            password: "admin123"
            autoSubmit: true
            submitMode: "auto"
            userSelector: "#username"
            passwordSelector: "#password"
            submitKeywords: "login,signin,continue"