Skip to content

Script Injection in Firefox

Nishant Bhasin edited this page Mar 19, 2020 · 2 revisions

There are tools that take js script and make it compact:

  • Webpack (this is what we use for firefox)
  • Browserify

Note:

  • The scripts to insert should also be added to the project but not added to any target.
  • Actual scripts goes in Client/Assets folder
  • All scripts gets the security token injected and are picked up by webpack
  • Concept:
    • Javascript (IIFE) → Old school way of private namespacing
    • Anything outside of a fuction is hackable in Javascript

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 scrip to the app but not to the target under the proper folder as described in step 1.

  3. At times you will need to modify UserScriptManager.swift for things related to Token etc. that we insert as a part of webpack config. This class also injects js script in the form of (WKUserScript) into the WKWebview.

  4. Once you have successfully inserted script

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

Important Files:

  • bootstraip.sh → Package.json → webpack.config.js → UserScriptManager.swift
Clone this wiki locally