Skip to content

Script Injection in Firefox

Garvan Keeley edited this page Mar 19, 2020 · 2 revisions

Injected JS is compacted into single scripts using webpack. There are 4 autogenerated webpacked js files.

Note:

  • The scripts to insert should also be added to the project but not added to any target.
  • The actual injected scripts are in Client/Assets folder. These are autogenerated.
  • All scripts get the security token injected. The autogenerated webpack scripts are wrapped in an IIFE that injects this token when swift loads them for injection.

Steps:

  1. Add the script you would like to inject in the proper folder

    • /Client/Frontend/UserContent/UserScripts/
      • AllFrames/
        • AtDocumentEnd/
        • AtDocumentStart/
      • MainFrame/
        • AtDocumentEnd/
        • AtDocumentStart

    The AllFrames, MainFrame folder tells the frame where the script gets inserted

    The location of the script is determined by the folder AtDocumentEnd, AtDocumentStart which tells webpack where the js script will be inserted

  2. Also, add the script to the app but not to the target under the proper folder as described in step 1.

  3. UserScriptManager.swift injects js script in the form of WKUserScript into the WKWebView. This file shouldn't need modification.

  4. Once you have successfully inserted script

    • run ./bootstrap.js
    • The folder should get updated with new compact scripts
      • Client/Assets/
    • Commit the changes to your branch

Important Files:

  • bootstrap.sh → package.json → webpack.config.js → UserScriptManager.swift
Clone this wiki locally